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

@ -18,23 +18,23 @@ extern Dialog *dialogRPG;
#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;
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)){
(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() */
@ -49,12 +49,11 @@ void interaction_available(Game *game)
/* 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))
{
(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() */
@ -81,7 +80,6 @@ void game_logic(Game *game) {
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,14 +9,9 @@
/* 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
{
typedef struct {
uint32_t x, y;
uint32_t w, h;
@ -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 */

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>
@ -25,7 +24,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
extern bopti_image_t player_face_img;
@ -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

@ -226,10 +226,8 @@ int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *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++ )
{
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,35 +301,32 @@ 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 */
if(!Data->hasPath)
continue; /* this NPC has a trajectory */
int NbPoints = Data->path_length + 1;
for(int v=0; v<NbPoints; v++)
{
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);

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;
@ -201,8 +195,9 @@ bool player_collision(Game *game, Direction direction,
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 */

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()