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

View file

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

View file

@ -1,10 +1,9 @@
#include "config.h"
#include <gint/cpu.h>
#include <gint/display.h> #include <gint/display.h>
#include <gint/keyboard.h> #include <gint/keyboard.h>
#include <gint/timer.h> #include <gint/timer.h>
#include <gint/cpu.h>
#include "config.h"
#if USB_FEATURE #if USB_FEATURE
#include <gint/usb-ff-bulk.h> #include <gint/usb-ff-bulk.h>
@ -12,11 +11,11 @@
#endif // USB_FEATURE #endif // USB_FEATURE
#if GRAYMODEOK #if GRAYMODEOK
#include <gint/gray.h> #include <gint/gray.h>
#endif //GRAYMODEOK #endif // GRAYMODEOK
#if DEBUGMODE #if DEBUGMODE
#include <gint/gdb.h> #include <gint/gdb.h>
#endif /*DEBUGMODE*/ #endif /*DEBUGMODE*/
#include "dialogs.h" #include "dialogs.h"
@ -25,7 +24,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
extern bopti_image_t player_face_img; extern bopti_image_t player_face_img;
@ -94,10 +92,10 @@ int update_time(void) {
} }
int main(void) { int main(void) {
#if DEBUGMODE #if DEBUGMODE
gdb_start_on_exception(); gdb_start_on_exception();
#endif /*DEBUGMODE*/ #endif /*DEBUGMODE*/
//__printf_enable_fp(); //__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, (int *)&game.player.life, "life");
events_bind_variable(&game.handler, &game.mana, "mana"); events_bind_variable(&game.handler, &game.mana, "mana");
//reload_npc(&game); // reload_npc(&game);
#if USB_FEATURE #if USB_FEATURE
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL}; usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
usb_open(interfaces, GINT_CALL_NULL); usb_open(interfaces, GINT_CALL_NULL);
#endif #endif
/* start grayscale engine */ /* start grayscale engine */
#if GRAYMODEOK #if GRAYMODEOK
dgray(DGRAY_ON); dgray(DGRAY_ON);
#endif #endif
dupdate(); dupdate();
getkey(); getkey();
@ -147,7 +145,7 @@ int main(void) {
dprint(10, 20, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", dprint(10, 20, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d",
1, worldRPG[1]->xmin, worldRPG[1]->ymin, 1, worldRPG[1]->xmin, worldRPG[1]->ymin,
worldRPG[1]->xmax, worldRPG[1]->ymax); worldRPG[1]->xmax, worldRPG[1]->ymax);
dprint(10, 30, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", dprint(10, 30, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d",
2, worldRPG[2]->xmin, worldRPG[2]->ymin, 2, worldRPG[2]->xmin, worldRPG[2]->ymin,
worldRPG[2]->xmax, worldRPG[2]->ymax); worldRPG[2]->xmax, worldRPG[2]->ymax);
dprint(10, 40, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", dprint(10, 40, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d",
@ -166,12 +164,13 @@ int main(void) {
{ {
dfont( NULL ); dfont( NULL );
for (int i=0; i<game.map_level->nbextradata; i++ ) 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", dprint( 10, 90+i*15, C_RED, "X= %d - Y= %d - T: %d - ID: %d
game.map_level->extradata[i].x, - S: %c", game.map_level->extradata[i].x,
game.map_level->extradata[i].y, game.map_level->extradata[i].y,
game.map_level->extradata[i].dialogID, game.map_level->extradata[i].dialogID,
game.map_level->dialogs[ game.map_level->extradata[i].dialogID ].ID, game.map_level->dialogs[
game.map_level->dialogs[ game.map_level->extradata[i].dialogID ].conclusion1[0] ); game.map_level->extradata[i].dialogID ].ID, game.map_level->dialogs[
game.map_level->extradata[i].dialogID ].conclusion1[0] );
} }
#endif*/ #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_milkman;
extern bopti_image_t tiny_npc_police; extern bopti_image_t tiny_npc_police;
//NPC *npcRPG; // NPC *npcRPG;
//uint32_t nbNPC = 0; // uint32_t nbNPC = 0;
float length(float x, float y) { return sqrtf(x * x + y * y); } 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)); memmove(npc, &npc[1], (nbNPC - pos - 1) * sizeof(NPC));
}*/ }*/
//Refactoring to make adding complexity cleaner // Refactoring to make adding complexity cleaner
void update_npcs([[maybe_unused]] Game *game) void update_npcs([[maybe_unused]] Game *game) {
{ for(uint32_t u = 0; u < game->map_level->nbNPC; u++) {
for( uint32_t u=0; u<game->map_level->nbNPC; u++ )
{
update_npc(&game->map_level->npcs[u]); update_npc(&game->map_level->npcs[u]);
} }
} }
@ -303,40 +301,37 @@ void npc_draw(Game *game) {
Player *pl = &game->player; Player *pl = &game->player;
size_t i; size_t i;
const bopti_image_t *npc_sprites[FACES] = { const bopti_image_t *npc_sprites[FACES] = {
&tiny_npc_male, &tiny_npc_male, &tiny_npc_female, &tiny_npc_milkman, &tiny_npc_police};
&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]; NPC *Data = &game->map_level->npcs[u];
/* Render the path if in debug*/ /* Render the path if in debug*/
#if DEBUGMODE #if DEBUGMODE
if(!Data->hasPath) continue; /* this NPC has a trajectory */ if(!Data->hasPath)
int NbPoints = Data->path_length+1; continue; /* this NPC has a trajectory */
for(int v=0; v<NbPoints; v++) int NbPoints = Data->path_length + 1;
{ for(int v = 0; v < NbPoints; v++) {
int16_t deltaX1=((int16_t) (Data->x + int16_t deltaX1 =
Data->xpath[v % NbPoints]) * PXSIZE) ((int16_t)(Data->x + Data->xpath[v % NbPoints]) * PXSIZE) -
-(int16_t) pl->wx; (int16_t)pl->wx;
int16_t deltaY1=((int16_t) (Data->y + int16_t deltaY1 =
Data->ypath[v % NbPoints]) * PXSIZE) ((int16_t)(Data->y + Data->ypath[v % NbPoints]) * PXSIZE) -
-(int16_t) pl->wy; (int16_t)pl->wy;
int16_t deltaX2=((int16_t) (Data->x + int16_t deltaX2 =
Data->xpath[(v+1) % NbPoints]) * PXSIZE) ((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints]) *
-(int16_t) pl->wx; PXSIZE) -
int16_t deltaY2=((int16_t) (Data->y + (int16_t)pl->wx;
Data->ypath[(v+1) % NbPoints]) * PXSIZE) int16_t deltaY2 =
-(int16_t) pl->wy; ((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints]) *
PXSIZE) -
dline( pl->px + deltaX1, pl->py + deltaY1,pl->px + deltaX2, (int16_t)pl->wy;
pl->py + deltaY2,PATH_COLOR);
} dline(pl->px + deltaX1, pl->py + deltaY1, pl->px + deltaX2,
#endif // DEBUGMODE pl->py + deltaY2, PATH_COLOR);
}
#endif // DEBUGMODE
int16_t delX = ((int16_t)(Data->curx * PXSIZE)) - (int16_t)pl->wx; int16_t delX = ((int16_t)(Data->curx * PXSIZE)) - (int16_t)pl->wx;
int16_t delY = ((int16_t)(Data->cury * PXSIZE)) - (int16_t)pl->wy; 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 SGN_Icon_img;
extern bopti_image_t INFO_Icon_img; extern bopti_image_t INFO_Icon_img;
const bopti_image_t *faces[FACES] = { const bopti_image_t *faces[FACES] = {&npc_male, &npc_female, &npc_milkman,
&npc_male, &npc_police};
&npc_female,
&npc_milkman,
&npc_police
};
const char one_px_mov[8] = { const char one_px_mov[8] = {
0, -1, /* Up */ 0, -1, /* Up */
@ -99,10 +95,10 @@ void player_action(Game *game) {
size_t i; size_t i;
/* already doing something, or can't do anything*/ /* 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 can do something */
/* we indicate that the player is occupied */ /* we indicate that the player is occupied */
game->player.isDoingAction = true; game->player.isDoingAction = true;
@ -123,9 +119,7 @@ void player_action(Game *game) {
/* when done we release the occupied status of the player */ /* when done we release the occupied status of the player */
game->player.isDoingAction = false; game->player.isDoingAction = false;
} } else {
else
{
/* we can do something (action IS with an NPC) */ /* we can do something (action IS with an NPC) */
/* we indicate that the player is occupied */ /* we indicate that the player is occupied */
game->player.isDoingAction = true; game->player.isDoingAction = true;
@ -198,11 +192,12 @@ bool player_collision(Game *game, Direction direction,
player->x = (worldX - map->xmin) * PXSIZE; player->x = (worldX - map->xmin) * PXSIZE;
player->y = (worldY - map->ymin) * PXSIZE; player->y = (worldY - map->ymin) * PXSIZE;
int on_walkable = map_get_walkable(game, player->x/T_WIDTH, int on_walkable = map_get_walkable(game, player->x / T_WIDTH,
player->y/T_HEIGHT); player->y / T_HEIGHT);
int speed = (on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX) ? int speed = (on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX)
walkable_speed[on_walkable] : 0; ? walkable_speed[on_walkable]
: 0;
/* if he's on a hard tile and we need to revert the changes as */ /* 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 */ /* 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 */ /* we update the list of NPCs in the current map */
/* to follow the trajectories */ /* to follow the trajectories */
//reload_npc(game); // reload_npc(game);
return false; return false;
} }

View file

@ -34,7 +34,8 @@ void player_draw(Game *game);
*/ */
void player_move(Game *game, Direction direction); 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); void player_action(Game *game);
/* player_collision() /* player_collision()