Run clang format

This commit is contained in:
mibi88 2024-07-30 18:21:22 +02:00
parent 2202ec6d38
commit 537e4d5e96
6 changed files with 102 additions and 119 deletions

View file

@ -13,28 +13,28 @@
extern bopti_image_t SignAction_img;
extern Dialog *dialogRPG;
//extern NPC *npcRPG;
//extern uint32_t nbNPC;
// extern NPC *npcRPG;
// extern uint32_t nbNPC;
#define MAX_INTERACTION_DISTANCE 12
#define MAX_INTERACTION_DISTANCE 12
void interaction_available(Game *game)
{
void interaction_available(Game *game) {
uint32_t i;
/*NPCs take priority over signs*/
for(uint32_t i=0; i<game->map_level->nbNPC; i++){
if(!game->map_level->npcs[i].has_dialogue) continue;
for(uint32_t i = 0; i < game->map_level->nbNPC; i++) {
if(!game->map_level->npcs[i].has_dialogue)
continue;
/* simple distance check along X and Y axis */
/* Be careful to use world coordinates, not local (i.e.map) ones */
if ((abs((int) game->player.wx -
(int) game->map_level->npcs[i].curx*PXSIZE )
< MAX_INTERACTION_DISTANCE*PXSIZE)
&& (abs((int) game->player.wy -
(int) game->map_level->npcs[i].cury*PXSIZE )
< MAX_INTERACTION_DISTANCE*PXSIZE)){
if((abs((int)game->player.wx -
(int)game->map_level->npcs[i].curx * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE) &&
(abs((int)game->player.wy -
(int)game->map_level->npcs[i].cury * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE)) {
/* the player can do something */
game->player.canDoSomething = true;
/* we mark the action for futur treatment in player_action() */
@ -45,16 +45,15 @@ void interaction_available(Game *game)
}
}
for(i = 0; i < game->map_level->nbSign; i++){
/* simple distance check along X and Y axis */
for(i = 0; i < game->map_level->nbSign; i++) {
/* simple distance check along X and Y axis */
/* Be careful to use world coordinates, not local (i.e.map) ones */
if ((abs((int) game->player.wx -
(int) game->map_level->signs[i].x*PXSIZE )
< MAX_INTERACTION_DISTANCE*PXSIZE)
&& (abs((int) game->player.wy -
(int) game->map_level->signs[i].y*PXSIZE )
< MAX_INTERACTION_DISTANCE*PXSIZE))
{
if((abs((int)game->player.wx -
(int)game->map_level->signs[i].x * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE) &&
(abs((int)game->player.wy -
(int)game->map_level->signs[i].y * PXSIZE) <
MAX_INTERACTION_DISTANCE * PXSIZE)) {
/* the player can do something */
game->player.canDoSomething = true;
/* we mark the action for future treatment in player_action() */
@ -74,14 +73,13 @@ void interaction_available(Game *game)
void game_logic(Game *game) {
update_npcs( game );
update_npcs(game);
/* we check if interactions are possible close to the player */
interaction_available(game);
}
void game_render_indicator(Game *game) {
/* nothing to do for the player so we quit */
if(game->player.canDoSomething == false)

View file

@ -9,16 +9,11 @@
/* The direction where the player is going to. */
typedef enum { D_UP, D_DOWN, D_LEFT, D_RIGHT } Direction;
typedef enum {
P_LEFTUP = -1,
P_CENTER = 0,
P_RIGHTDOWN = 1
} Checkpos;
typedef enum { P_LEFTUP = -1, P_CENTER = 0, P_RIGHTDOWN = 1 } Checkpos;
typedef struct
{
uint32_t x,y;
uint32_t w,h;
typedef struct {
uint32_t x, y;
uint32_t w, h;
} Collider;
@ -75,12 +70,12 @@ typedef struct {
uint32_t needAction;
} Sign;
typedef struct
{
typedef struct {
/* current coordinates of the NPC */
float curx, cury;
/* initial coordinates of the NPC (needed to get absolute coordinates of path) */
/* initial coordinates of the NPC (needed to get absolute coordinates of
* path) */
uint32_t x;
uint32_t y;
/* id of it's face */
@ -112,7 +107,7 @@ typedef struct
uint16_t __padding;
} NPC;
typedef struct{
typedef struct {
Collider collider;
/*if the portal tps to an interior or exterior map*/
uint16_t tp_interior;

View file

@ -1,10 +1,9 @@
#include "config.h"
#include <gint/cpu.h>
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/timer.h>
#include <gint/cpu.h>
#include "config.h"
#if USB_FEATURE
#include <gint/usb-ff-bulk.h>
@ -12,11 +11,11 @@
#endif // USB_FEATURE
#if GRAYMODEOK
#include <gint/gray.h>
#endif //GRAYMODEOK
#include <gint/gray.h>
#endif // GRAYMODEOK
#if DEBUGMODE
#include <gint/gdb.h>
#include <gint/gdb.h>
#endif /*DEBUGMODE*/
#include "dialogs.h"
@ -25,7 +24,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
extern bopti_image_t player_face_img;
@ -95,9 +93,9 @@ int update_time(void) {
int main(void) {
#if DEBUGMODE
gdb_start_on_exception();
#endif /*DEBUGMODE*/
#if DEBUGMODE
gdb_start_on_exception();
#endif /*DEBUGMODE*/
//__printf_enable_fp();
@ -113,18 +111,18 @@ int main(void) {
events_bind_variable(&game.handler, (int *)&game.player.life, "life");
events_bind_variable(&game.handler, &game.mana, "mana");
//reload_npc(&game);
// reload_npc(&game);
#if USB_FEATURE
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
usb_open(interfaces, GINT_CALL_NULL);
#endif
#if USB_FEATURE
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
usb_open(interfaces, GINT_CALL_NULL);
#endif
/* start grayscale engine */
#if GRAYMODEOK
dgray(DGRAY_ON);
#endif
#if GRAYMODEOK
dgray(DGRAY_ON);
#endif
dupdate();
getkey();
@ -166,12 +164,13 @@ int main(void) {
{
dfont( NULL );
for (int i=0; i<game.map_level->nbextradata; i++ )
dprint( 10, 90+i*15, C_RED, "X= %d - Y= %d - T: %d - ID: %d - S: %c",
game.map_level->extradata[i].x,
dprint( 10, 90+i*15, C_RED, "X= %d - Y= %d - T: %d - ID: %d
- S: %c", game.map_level->extradata[i].x,
game.map_level->extradata[i].y,
game.map_level->extradata[i].dialogID,
game.map_level->dialogs[ game.map_level->extradata[i].dialogID ].ID,
game.map_level->dialogs[ game.map_level->extradata[i].dialogID ].conclusion1[0] );
game.map_level->dialogs[
game.map_level->extradata[i].dialogID ].ID, game.map_level->dialogs[
game.map_level->extradata[i].dialogID ].conclusion1[0] );
}
#endif*/

View file

@ -16,8 +16,8 @@ extern bopti_image_t tiny_npc_female;
extern bopti_image_t tiny_npc_milkman;
extern bopti_image_t tiny_npc_police;
//NPC *npcRPG;
//uint32_t nbNPC = 0;
// NPC *npcRPG;
// uint32_t nbNPC = 0;
float length(float x, float y) { return sqrtf(x * x + y * y); }
@ -225,11 +225,9 @@ int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) {
memmove(npc, &npc[1], (nbNPC - pos - 1) * sizeof(NPC));
}*/
//Refactoring to make adding complexity cleaner
void update_npcs([[maybe_unused]] Game *game)
{
for( uint32_t u=0; u<game->map_level->nbNPC; u++ )
{
// Refactoring to make adding complexity cleaner
void update_npcs([[maybe_unused]] Game *game) {
for(uint32_t u = 0; u < game->map_level->nbNPC; u++) {
update_npc(&game->map_level->npcs[u]);
}
}
@ -303,40 +301,37 @@ void npc_draw(Game *game) {
Player *pl = &game->player;
size_t i;
const bopti_image_t *npc_sprites[FACES] = {
&tiny_npc_male,
&tiny_npc_female,
&tiny_npc_milkman,
&tiny_npc_police
};
&tiny_npc_male, &tiny_npc_female, &tiny_npc_milkman, &tiny_npc_police};
for (uint32_t u=0; u<game->map_level->nbNPC; u++)
{
for(uint32_t u = 0; u < game->map_level->nbNPC; u++) {
NPC *Data = &game->map_level->npcs[u];
/* Render the path if in debug*/
#if DEBUGMODE
if(!Data->hasPath) continue; /* this NPC has a trajectory */
int NbPoints = Data->path_length+1;
for(int v=0; v<NbPoints; v++)
{
/* Render the path if in debug*/
#if DEBUGMODE
if(!Data->hasPath)
continue; /* this NPC has a trajectory */
int NbPoints = Data->path_length + 1;
for(int v = 0; v < NbPoints; v++) {
int16_t deltaX1=((int16_t) (Data->x +
Data->xpath[v % NbPoints]) * PXSIZE)
-(int16_t) pl->wx;
int16_t deltaY1=((int16_t) (Data->y +
Data->ypath[v % NbPoints]) * PXSIZE)
-(int16_t) pl->wy;
int16_t deltaX2=((int16_t) (Data->x +
Data->xpath[(v+1) % NbPoints]) * PXSIZE)
-(int16_t) pl->wx;
int16_t deltaY2=((int16_t) (Data->y +
Data->ypath[(v+1) % NbPoints]) * PXSIZE)
-(int16_t) pl->wy;
int16_t deltaX1 =
((int16_t)(Data->x + Data->xpath[v % NbPoints]) * PXSIZE) -
(int16_t)pl->wx;
int16_t deltaY1 =
((int16_t)(Data->y + Data->ypath[v % NbPoints]) * PXSIZE) -
(int16_t)pl->wy;
int16_t deltaX2 =
((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints]) *
PXSIZE) -
(int16_t)pl->wx;
int16_t deltaY2 =
((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints]) *
PXSIZE) -
(int16_t)pl->wy;
dline( pl->px + deltaX1, pl->py + deltaY1,pl->px + deltaX2,
pl->py + deltaY2,PATH_COLOR);
}
#endif // DEBUGMODE
dline(pl->px + deltaX1, pl->py + deltaY1, pl->px + deltaX2,
pl->py + deltaY2, PATH_COLOR);
}
#endif // DEBUGMODE
int16_t delX = ((int16_t)(Data->curx * PXSIZE)) - (int16_t)pl->wx;
int16_t delY = ((int16_t)(Data->cury * PXSIZE)) - (int16_t)pl->wy;

View file

@ -17,12 +17,8 @@ extern bopti_image_t npc_police;
extern bopti_image_t SGN_Icon_img;
extern bopti_image_t INFO_Icon_img;
const bopti_image_t *faces[FACES] = {
&npc_male,
&npc_female,
&npc_milkman,
&npc_police
};
const bopti_image_t *faces[FACES] = {&npc_male, &npc_female, &npc_milkman,
&npc_police};
const char one_px_mov[8] = {
0, -1, /* Up */
@ -99,10 +95,10 @@ void player_action(Game *game) {
size_t i;
/* already doing something, or can't do anything*/
if(game->player.isDoingAction || !game->player.canDoSomething) return;
if(game->player.isDoingAction || !game->player.canDoSomething)
return;
if(!game->player.isInteractingWithNPC)
{
if(!game->player.isInteractingWithNPC) {
/* we can do something */
/* we indicate that the player is occupied */
game->player.isDoingAction = true;
@ -123,9 +119,7 @@ void player_action(Game *game) {
/* when done we release the occupied status of the player */
game->player.isDoingAction = false;
}
else
{
} else {
/* we can do something (action IS with an NPC) */
/* we indicate that the player is occupied */
game->player.isDoingAction = true;
@ -198,11 +192,12 @@ bool player_collision(Game *game, Direction direction,
player->x = (worldX - map->xmin) * PXSIZE;
player->y = (worldY - map->ymin) * PXSIZE;
int on_walkable = map_get_walkable(game, player->x/T_WIDTH,
player->y/T_HEIGHT);
int on_walkable = map_get_walkable(game, player->x / T_WIDTH,
player->y / T_HEIGHT);
int speed = (on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX) ?
walkable_speed[on_walkable] : 0;
int speed = (on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX)
? walkable_speed[on_walkable]
: 0;
/* if he's on a hard tile and we need to revert the changes as */
/* tile on the next side of the border is not walkable */
@ -218,7 +213,7 @@ bool player_collision(Game *game, Direction direction,
/* we update the list of NPCs in the current map */
/* to follow the trajectories */
//reload_npc(game);
// reload_npc(game);
return false;
}

View file

@ -34,7 +34,8 @@ void player_draw(Game *game);
*/
void player_move(Game *game, Direction direction);
/*Tries to do an action based on previously set flags (called if the shift key is pressed)*/
/*Tries to do an action based on previously set flags (called if the shift key
* is pressed)*/
void player_action(Game *game);
/* player_collision()