diff --git a/.clang-format b/.clang-format index 89efd2d..196c51c 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,6 @@ BasedOnStyle: LLVM IndentWidth: 4 PointerAlignment: Right SpaceBeforeAssignmentOperators: true -BreakBeforeBinaryOperators: true SpaceBeforeRangeBasedForLoopColon: false SpaceInEmptyBlock: false SpaceInEmptyParentheses: false @@ -10,3 +9,4 @@ SpaceBeforeParens: Never IndentCaseBlocks: true IncludeBlocks: Regroup AllowShortBlocksOnASingleLine: Empty +ColumnLimit: 80 diff --git a/src/dialogs.c b/src/dialogs.c index d9f6fbb..241e38f 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -45,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. */ @@ -145,11 +145,10 @@ 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,11 +179,10 @@ 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/events.c b/src/events.c index 1e65db9..ff66087 100644 --- a/src/events.c +++ b/src/events.c @@ -39,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 c830a88..4898846 100644 --- a/src/game.c +++ b/src/game.c @@ -26,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() */ @@ -46,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/map.c b/src/map.c index 63e33c0..ea9be31 100644 --- a/src/map.c +++ b/src/map.c @@ -81,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 @@ -173,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 @@ -220,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; } @@ -229,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/npc.c b/src/npc.c index 0e66f50..d8abd3e 100644 --- a/src/npc.c +++ b/src/npc.c @@ -186,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; } @@ -315,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); @@ -369,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, @@ -395,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/player.c b/src/player.c index 4e5ca01..8b49fa0 100644 --- a/src/player.c +++ b/src/player.c @@ -67,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. */ @@ -104,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 */ @@ -137,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; @@ -147,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