diff --git a/.clang-format b/.clang-format index bf85b5a..89efd2d 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,12 @@ BasedOnStyle: LLVM IndentWidth: 4 PointerAlignment: Right -SpaceBeforeParens: Custom -SpaceBeforeParensOptions: - AfterControlStatements: false - +SpaceBeforeAssignmentOperators: true +BreakBeforeBinaryOperators: true +SpaceBeforeRangeBasedForLoopColon: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpaceBeforeParens: Never +IndentCaseBlocks: true +IncludeBlocks: Regroup +AllowShortBlocksOnASingleLine: Empty diff --git a/src/dialogs.c b/src/dialogs.c index 657e940..d9f6fbb 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -1,15 +1,14 @@ #include "dialogs.h" -#include -#include - -#include - #include "config.h" #include "events.h" #include "game.h" #include "npc.h" +#include +#include +#include + #define BOX_HEIGHT (F_HEIGHT / PXSIZE + 8) #define CHOICE_BOX_HEIGHT 10 @@ -46,8 +45,8 @@ int dialogs_text_opt(Game *game, bopti_image_t *face, char *text, dfont(&FONT_USED); unsigned int i, n, y = PXSIZE, l = 0; int line_max_chars, return_int = 0; - unsigned int max_lines_amount = - (BOX_HEIGHT - 2) * PXSIZE / (FONT_USED.line_height + PXSIZE); + unsigned int max_lines_amount + = (BOX_HEIGHT - 2) * PXSIZE / (FONT_USED.line_height + PXSIZE); const char *c; if(start_anim) { /* Run a little fancy animation. */ @@ -146,10 +145,11 @@ int dialogs_text_opt(Game *game, bopti_image_t *face, char *text, /* If we drew one entire screen. */ /* Wait that the SHIFT key is pressed if we should. */ if(wait_continue) { - while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & - ~GETKEY_MOD_ALPHA, + while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT + & ~GETKEY_MOD_ALPHA, NULL) - .key != KEY_SHIFT) { + .key + != KEY_SHIFT) { sleep(); } } @@ -180,10 +180,11 @@ int dialogs_text_opt(Game *game, bopti_image_t *face, char *text, if(update_screen) blit(); if(wait_continue) { - while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & - ~GETKEY_MOD_ALPHA, + while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT + & ~GETKEY_MOD_ALPHA, NULL) - .key != KEY_SHIFT) { + .key + != KEY_SHIFT) { sleep(); } } diff --git a/src/dialogs.h b/src/dialogs.h index 86be96e..dae2adf 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -4,6 +4,7 @@ #include "config.h" #include "game.h" #include "map.h" + #include #include diff --git a/src/events.c b/src/events.c index df6ba9c..1e65db9 100644 --- a/src/events.c +++ b/src/events.c @@ -1,4 +1,5 @@ #include "events.h" + #include #include @@ -38,8 +39,8 @@ int _op_mod(int a, int b) { return a % b; } -int (*_operations[OP_AMOUNT])(int, int) = {_op_null, _op_set, _op_add, _op_sub, - _op_div, _op_mul, _op_mod}; +int (*_operations[OP_AMOUNT])(int, int) + = {_op_null, _op_set, _op_add, _op_sub, _op_div, _op_mul, _op_mod}; #define MIN(a, b) a < b ? a : b diff --git a/src/game.c b/src/game.c index a2a3020..c830a88 100644 --- a/src/game.c +++ b/src/game.c @@ -1,8 +1,8 @@ #include "game.h" -#include "map.h" - #include "config.h" +#include "map.h" +#include "npc.h" #include #include @@ -10,8 +10,6 @@ #include #include -#include "npc.h" - extern bopti_image_t SignAction_img; extern Dialog *dialogRPG; @@ -28,13 +26,13 @@ void game_logic(Game *game) { for(uint32_t i = 0; i < game->map_level->nbextradata; 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->extradata[i].x * PXSIZE) < - MAX_INTERACTION_DISTANCE * PXSIZE) && - (abs((int)game->player.wy - - (int)game->map_level->extradata[i].y * PXSIZE) < - MAX_INTERACTION_DISTANCE * PXSIZE) && - strcmp(game->map_level->extradata[i].type, "NPC") != 0) { + if((abs((int)game->player.wx + - (int)game->map_level->extradata[i].x * PXSIZE) + < MAX_INTERACTION_DISTANCE * PXSIZE) + && (abs((int)game->player.wy + - (int)game->map_level->extradata[i].y * PXSIZE) + < MAX_INTERACTION_DISTANCE * PXSIZE) + && strcmp(game->map_level->extradata[i].type, "NPC") != 0) { /* the player can do something */ game->player.canDoSomething = true; /* we mark the action for futur treatment in player_action() */ @@ -48,11 +46,11 @@ void game_logic(Game *game) { for(uint32_t i = 0; i < nbNPC; 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)npcRPG[i].curx * PXSIZE) < - MAX_INTERACTION_DISTANCE * PXSIZE) && - (abs((int)game->player.wy - (int)npcRPG[i].cury * PXSIZE) < - MAX_INTERACTION_DISTANCE * PXSIZE) && - strcmp(game->map_level->extradata[i].type, "NPC") != 0) { + if((abs((int)game->player.wx - (int)npcRPG[i].curx * PXSIZE) + < MAX_INTERACTION_DISTANCE * PXSIZE) + && (abs((int)game->player.wy - (int)npcRPG[i].cury * PXSIZE) + < MAX_INTERACTION_DISTANCE * PXSIZE) + && strcmp(game->map_level->extradata[i].type, "NPC") != 0) { /* the player can do something */ game->player.canDoSomething = true; /* we mark the action for futur treatment in player_action() */ diff --git a/src/game.h b/src/game.h index e03c385..4af3152 100644 --- a/src/game.h +++ b/src/game.h @@ -1,11 +1,11 @@ #ifndef GAME_H #define GAME_H +#include "events.h" + #include #include -#include "events.h" - /* The direction where the player is going to. */ typedef enum { D_UP, D_DOWN, D_LEFT, D_RIGHT } Direction; diff --git a/src/main.c b/src/main.c index 97a2ccc..8dde42b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,15 +1,14 @@ -#include -#include -#include -#include - -#include - #include "config.h" #include "events.h" #include "npc.h" +#include +#include +#include +#include +#include + #if USB_FEATURE #include #include @@ -19,13 +18,12 @@ #include #endif // GRAYMODEOK -#include -#include - +#include "dialogs.h" #include "game.h" #include "mapdata.h" -#include "dialogs.h" +#include +#include extern bopti_image_t player_face_img; diff --git a/src/map.c b/src/map.c index 78901c4..63e33c0 100644 --- a/src/map.c +++ b/src/map.c @@ -1,4 +1,5 @@ #include "map.h" + #include "config.h" #include "game.h" @@ -80,8 +81,8 @@ void map_render(Game *game) { for(x = 0; x < dw; x++) { /* I get the tile number if his position is inside the map. Then * I draw it. */ - if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0 && - ty + y < map_level->h) { + if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0 + && ty + y < map_level->h) { /* index of the current tile */ current_index = (y + ty) * map_level->w + tx + x; /* we get the ID of the tile in the current drawable layers @@ -172,8 +173,8 @@ void map_render_by_layer(Game *game, int layer) { for(x = 0; x < dw; x++) { /* I get the tile number if his position is inside the map. Then * I draw it. */ - if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0 && - ty + y < map_level->h) { + if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0 + && ty + y < map_level->h) { /* index of the current tile */ int currentIndex = (y + ty) * map_level->w + tx + x; /* we get the ID of the tile in the current drawable layers @@ -219,8 +220,8 @@ short int map_get_walkable(Game *game, int x, int y) { /* return the pointer to the map containing the given position */ Map *map_get_for_coordinates(Game *game, int x, int y) { /* check if the current map contains the point */ - if(x >= (int)game->map_level->xmin && x < (int)game->map_level->xmax && - y >= (int)game->map_level->ymin && y < (int)game->map_level->ymax) { + if(x >= (int)game->map_level->xmin && x < (int)game->map_level->xmax + && y >= (int)game->map_level->ymin && y < (int)game->map_level->ymax) { return game->map_level; } @@ -228,8 +229,8 @@ Map *map_get_for_coordinates(Game *game, int x, int y) { int i = 0; Map *current = worldRPG[i]; do { - if(x >= (int)current->xmin && x < (int)current->xmax && - y >= (int)current->ymin && y < (int)current->ymax) + if(x >= (int)current->xmin && x < (int)current->xmax + && y >= (int)current->ymin && y < (int)current->ymax) return current; i++; current = worldRPG[i]; diff --git a/src/mapdata.h b/src/mapdata.h index 7b63f8c..0b6d0e4 100644 --- a/src/mapdata.h +++ b/src/mapdata.h @@ -2,6 +2,7 @@ #define MAPDATA_H #include "game.h" + #include extern Map *worldRPG[]; diff --git a/src/npc.c b/src/npc.c index ac4ec35..0e66f50 100644 --- a/src/npc.c +++ b/src/npc.c @@ -1,11 +1,12 @@ #include "npc.h" + #include "config.h" #include "dialogs.h" #include "game.h" #include "map.h" + #include #include /*debug*/ - #include #include #include @@ -185,8 +186,8 @@ int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) { if(att_score < gscore[j * w + i]) { came_from[j * w + i] = by * w + bx; gscore[j * w + i] = att_score; - fscore[j * w + i] = - att_score + round(length(dest_x - i, dest_y - j)); + fscore[j * w + i] + = att_score + round(length(dest_x - i, dest_y - j)); if(visited[j * w + i]) visited[j * w + i] = 0; } @@ -314,20 +315,20 @@ void npc_draw(Game *game) { 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); @@ -368,23 +369,23 @@ void OLD_npc_draw(Game *game) { 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)player->wx; - int16_t deltaY1 = - ((int16_t)(Data->y + Data->ypath[v % NbPoints]) * - PXSIZE) - - (int16_t)player->wy; + int16_t deltaX1 + = ((int16_t)(Data->x + Data->xpath[v % NbPoints]) + * PXSIZE) + - (int16_t)player->wx; + int16_t deltaY1 + = ((int16_t)(Data->y + Data->ypath[v % NbPoints]) + * PXSIZE) + - (int16_t)player->wy; - int16_t deltaX2 = - ((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints]) * - PXSIZE) - - (int16_t)player->wx; - int16_t deltaY2 = - ((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints]) * - PXSIZE) - - (int16_t)player->wy; + int16_t deltaX2 + = ((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints]) + * PXSIZE) + - (int16_t)player->wx; + int16_t deltaY2 + = ((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints]) + * PXSIZE) + - (int16_t)player->wy; dline(player->px + deltaX1, player->py + deltaY1, player->px + deltaX2, player->py + deltaY2, @@ -394,10 +395,10 @@ void OLD_npc_draw(Game *game) { #endif // DEBUGMODE - int16_t deltaX = - ((int16_t)(Data->x * PXSIZE)) - (int16_t)player->wx; - int16_t deltaY = - ((int16_t)(Data->y * PXSIZE)) - (int16_t)player->wy; + int16_t deltaX + = ((int16_t)(Data->x * PXSIZE)) - (int16_t)player->wx; + int16_t deltaY + = ((int16_t)(Data->y * PXSIZE)) - (int16_t)player->wy; dimage(player->px - P_WIDTH / 2 + deltaX, player->py - P_HEIGHT / 2 + deltaY, &tiny_npc_male); } diff --git a/src/npc.h b/src/npc.h index aa26b32..3eff7c8 100644 --- a/src/npc.h +++ b/src/npc.h @@ -1,12 +1,12 @@ #ifndef NPC_H #define NPC_H -#include -#include - #include "game.h" #include "memory.h" +#include +#include + enum { NPC_NONE = 0, diff --git a/src/player.c b/src/player.c index fc90f44..4e5ca01 100644 --- a/src/player.c +++ b/src/player.c @@ -1,9 +1,11 @@ #include "player.h" + #include "config.h" #include "dialogs.h" #include "game.h" #include "map.h" #include "npc.h" + #include extern bopti_image_t player_male_img; @@ -65,8 +67,8 @@ void player_move(Game *game, Direction direction) { player_fix_position(game, dx, dy); } else { - if(player_collision(game, direction, P_RIGHTDOWN) || - player_collision(game, direction, P_LEFTUP)) { + if(player_collision(game, direction, P_RIGHTDOWN) + || player_collision(game, direction, P_LEFTUP)) { /* If the will collide with the edges of the player. */ /* I fix his position so he won't be partially in the tile. */ @@ -102,8 +104,8 @@ void player_action(Game *game) { /* we indicate that the player is occupied */ game->player.isDoingAction = true; - ExtraData *currentData = - &game->map_level->extradata[game->player.whichAction]; + ExtraData *currentData + = &game->map_level->extradata[game->player.whichAction]; /* we use the correct image as per the class of the item */ @@ -135,8 +137,8 @@ void player_action(Game *game) { /* when done we release the occupied status of the player */ game->player.isDoingAction = false; - } else if(game->player.canDoSomething && - game->player.isInteractingWithNPC) { + } else if(game->player.canDoSomething + && game->player.isInteractingWithNPC) { /* we can do something (action IS with an NPC) */ /* we indicate that the player is occupied */ game->player.isDoingAction = true; @@ -145,8 +147,8 @@ void player_action(Game *game) { /* we use the correct image as per the class of the item */ - ExtraData *currentData = - &game->map_level->extradata[game->player.whichAction]; + ExtraData *currentData + = &game->map_level->extradata[game->player.whichAction]; bopti_image_t *face = &npc_male; /* It's a NPC */ /* (Mibi88) TODO: Use string hash + strcmp if the hashes match for diff --git a/src/player.h b/src/player.h index 82ae0db..a0a2800 100644 --- a/src/player.h +++ b/src/player.h @@ -4,6 +4,7 @@ #include "config.h" #include "game.h" #include "memory.h" + #include typedef struct {