From 0974ddf65bde2ece5fc908e67cf2e8871575d333 Mon Sep 17 00:00:00 2001 From: Periicles Date: Tue, 28 May 2024 10:39:50 +0200 Subject: [PATCH 1/2] Fix all compilation warnings and errors. --- src/utils/create/raycasting_entities.c | 1 + src/utils/display/perso.c | 2 ++ src/utils/display/window.c | 4 ++-- src/utils/raycasting/define_wall.c | 6 +++--- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utils/create/raycasting_entities.c b/src/utils/create/raycasting_entities.c index 6d9a9cd..7aee527 100644 --- a/src/utils/create/raycasting_entities.c +++ b/src/utils/create/raycasting_entities.c @@ -10,6 +10,7 @@ entity_t *add_entity (char *texture_path, sfVector2f position, sfIntRect dimensions, int map_id) { + (void)map_id; entity_t *entity = malloc(sizeof(entity_t)); if (entity == NULL) return NULL; diff --git a/src/utils/display/perso.c b/src/utils/display/perso.c index 4ae248c..52cec3f 100644 --- a/src/utils/display/perso.c +++ b/src/utils/display/perso.c @@ -5,6 +5,8 @@ ** perso */ +#include + #include "game.h" int is_colliding(game_t *game, sfVector2f pos, sfVector2f offset); diff --git a/src/utils/display/window.c b/src/utils/display/window.c index b640089..ae21388 100644 --- a/src/utils/display/window.c +++ b/src/utils/display/window.c @@ -12,8 +12,8 @@ void display_window(game_t *game) if (game->menu == 0) sfRenderWindow_drawRectangleShape(game->window->window, game->window->rect[0], NULL); - else if (game->menu >= 5 && (game->menu < 10 || game->menu % 10 == 6 || - game->menu / 10 % 10 == 6) || game->menu == 42 || game->menu == -42) { + else if (game->menu >= 5 && ((game->menu < 10 || game->menu % 10 == 6 || + game->menu / 10 % 10 == 6) || game->menu == 42 || game->menu == -42)) { sfRenderWindow_drawSprite(game->window->window, game->map->sprite, NULL); } diff --git a/src/utils/raycasting/define_wall.c b/src/utils/raycasting/define_wall.c index 06cd0ba..196d144 100644 --- a/src/utils/raycasting/define_wall.c +++ b/src/utils/raycasting/define_wall.c @@ -75,9 +75,9 @@ void define_wall_y (game_t *game, float i) void define_wall (game_t *game, float i) { - raycast_map_t map = game->raycasting->maps[game->raycasting->selected_map]; - int x_detect = game->raycasting->rays[(int) i]->x_detect; - int y_detect = game->raycasting->rays[(int) i]->y_detect; + // raycast_map_t map = game->raycasting->maps[game->raycasting->selected_map]; + // int x_detect = game->raycasting->rays[(int) i]->x_detect; + // int y_detect = game->raycasting->rays[(int) i]->y_detect; int wall_orientation = check_wall_orientation(game, i); From 8207562a6641d4f8081854388a65e26ff3a92e88 Mon Sep 17 00:00:00 2001 From: Periicles Date: Sun, 2 Jun 2024 18:46:52 +0200 Subject: [PATCH 2/2] CODING-STYLE Still 604 to fix --- include/buttons.h | 42 ++++++------- include/clocks.h | 10 ++-- include/dialog.h | 22 +++---- include/end.h | 26 ++++---- include/game.h | 53 ++++++++--------- include/game_functions.h | 32 +++++----- include/game_menu.h | 56 +++++++++--------- include/inventory.h | 20 +++---- include/keys.h | 26 ++++---- include/map.h | 22 +++---- include/mobs.h | 44 +++++++------- include/network.h | 20 +++---- include/npc.h | 34 +++++------ include/overlay.h | 29 +++++---- include/params.h | 98 +++++++++++++++---------------- include/params_fonctions.h | 32 +++++----- include/perso.h | 44 +++++++------- include/raycasting.h | 98 +++++++++++++++---------------- include/save.h | 18 +++--- include/songs.h | 10 ++-- include/start.h | 4 +- include/window.h | 18 +++--- src/main.c | 6 +- src/save/save.c | 2 +- src/save/tab_handling.c | 6 +- src/save/write_save.c | 8 +-- src/start_game.c | 9 +-- src/utils/raycasting/move.c | 20 ++----- src/utils/raycasting/raycasting.c | 24 +++----- src/utils/raycasting/sort_walls.c | 4 +- 30 files changed, 409 insertions(+), 428 deletions(-) diff --git a/include/buttons.h b/include/buttons.h index 84e757e..f9026c3 100644 --- a/include/buttons.h +++ b/include/buttons.h @@ -10,27 +10,27 @@ #include "rpg.h" - enum stats { - none, - HOVER, - ACTIVE, - RELEASE, - }; +enum stats { + none, + HOVER, + ACTIVE, + RELEASE, +}; - typedef struct { - sfVector2f pos; - sfVector2f size; - sfTexture *texture; - sfSprite *sprite; - sfRectangleShape *rect; - sfIntRect rect_text; - sfColor color; - sfText *text; - sfFont *font; - sfVector2f text_pos; - char *str; - enum stats state; - void (*callback)(void *); - } buttons_t; +typedef struct { + sfVector2f pos; + sfVector2f size; + sfTexture *texture; + sfSprite *sprite; + sfRectangleShape *rect; + sfIntRect rect_text; + sfColor color; + sfText *text; + sfFont *font; + sfVector2f text_pos; + char *str; + enum stats state; + void (*callback)(void *); +} buttons_t; #endif /* !BUTTONS_H_ */ diff --git a/include/clocks.h b/include/clocks.h index 17bfbc8..c91af2c 100644 --- a/include/clocks.h +++ b/include/clocks.h @@ -10,10 +10,10 @@ #include "game.h" - typedef struct { - sfClock *clock; - sfTime time; - float seconds; - } clocks_t; +typedef struct { + sfClock *clock; + sfTime time; + float seconds; +} clocks_t; #endif /* !CLOCKS_H_ */ diff --git a/include/dialog.h b/include/dialog.h index 09b50e2..a71d10e 100644 --- a/include/dialog.h +++ b/include/dialog.h @@ -10,16 +10,16 @@ #include "game.h" - typedef struct { - char **dialog_text; - sfTexture *texture; - sfSprite *sprite; - sfText *text; - sfFont *font; - sfVector2f pos; - sfClock *clock; - sfTime time; - float seconds; - } dialog_box_t; +typedef struct { + char **dialog_text; + sfTexture *texture; + sfSprite *sprite; + sfText *text; + sfFont *font; + sfVector2f pos; + sfClock *clock; + sfTime time; + float seconds; +} dialog_box_t; #endif /* !DIALOG_H_ */ diff --git a/include/end.h b/include/end.h index 9c6a8b3..4e1f5e4 100644 --- a/include/end.h +++ b/include/end.h @@ -10,18 +10,18 @@ #include "rpg.h" - typedef struct s_end { - sfRectangleShape *container; - sfRectangleShape *content; - sfText *text; - sfFont *font; - sfVector2f pos; - sfVector2f size; - sfVector2f pos_text; - sfVector2f size_text; - sfColor color; - sfColor color_text; - int is_end; - } end_t; +typedef struct s_end { + sfRectangleShape *container; + sfRectangleShape *content; + sfText *text; + sfFont *font; + sfVector2f pos; + sfVector2f size; + sfVector2f pos_text; + sfVector2f size_text; + sfColor color; + sfColor color_text; + int is_end; +} end_t; #endif /* !END_H_ */ diff --git a/include/game.h b/include/game.h index a4fcfba..029f163 100644 --- a/include/game.h +++ b/include/game.h @@ -26,35 +26,34 @@ #include "clocks.h" #include "network.h" #include "end.h" - - typedef struct { - window_t *window; - map_t *map; - perso_t *perso; - mobs_t **mobs; - buttons_t **start; - buttons_t *go_back; - params_t *params; - keys_t *keys; - int menu; - game_menu_t *game_menu; - save_t *save; - inventory_t *inventory; - overlay_t *overlay; - npc_t **npc; - dialog_box_t *dialogs; - clocks_t *clock; - network_t *network; - raycasting_t *raycasting; - bool is_raycasting; - end_t *win; - end_t *loose; - bool is_finished; - int nb_mob_killed; - } game_t; - #include "start.h" #include "params_fonctions.h" #include "game_functions.h" +typedef struct { + window_t *window; + map_t *map; + perso_t *perso; + mobs_t **mobs; + buttons_t **start; + buttons_t *go_back; + params_t *params; + keys_t *keys; + int menu; + game_menu_t *game_menu; + save_t *save; + inventory_t *inventory; + overlay_t *overlay; + npc_t **npc; + dialog_box_t *dialogs; + clocks_t *clock; + network_t *network; + raycasting_t *raycasting; + bool is_raycasting; + end_t *win; + end_t *loose; + bool is_finished; + int nb_mob_killed; +} game_t; + #endif /* !GAME_H_ */ diff --git a/include/game_functions.h b/include/game_functions.h index 279e90e..e505b5e 100644 --- a/include/game_functions.h +++ b/include/game_functions.h @@ -10,23 +10,23 @@ #include "game.h" - void change_to_inventory(game_t *game); - void change_to_character(game_t *game); - void change_to_option(game_t *game); - void exit_start_all(game_t *game); - void change_to_quest(game_t *game); +void change_to_inventory(game_t *game); +void change_to_character(game_t *game); +void change_to_option(game_t *game); +void exit_start_all(game_t *game); +void change_to_quest(game_t *game); - typedef struct game_functions_s { - void (*function)(game_t *game); - } game_functions_t; +typedef struct game_functions_s { + void (*function)(game_t *game); +} game_functions_t; - static const game_functions_t MENU_FLAGS[] = { - {function : &change_to_inventory}, - {function : &change_to_character}, - {function : &change_to_quest}, - {function : &change_to_option}, - {function : &exit_start_all}, - {function : NULL}, - }; +static const game_functions_t MENU_FLAGS[] = { + {function : &change_to_inventory}, + {function : &change_to_character}, + {function : &change_to_quest}, + {function : &change_to_option}, + {function : &exit_start_all}, + {function : NULL}, +}; #endif /* !GAME_FUNCTIONS_H_ */ diff --git a/include/game_menu.h b/include/game_menu.h index a96518b..2e1d108 100644 --- a/include/game_menu.h +++ b/include/game_menu.h @@ -11,36 +11,36 @@ #include "rpg.h" #include "buttons.h" - typedef struct { - sfRectangleShape *container; - buttons_t **buttons; - } sidebar_t; +typedef struct { + sfRectangleShape *container; + buttons_t **buttons; +} sidebar_t; - typedef struct { - sfText **name; - sfText **value; - } character_t; +typedef struct { + sfText **name; + sfText **value; +} character_t; - typedef struct { - sfRectangleShape *container; - sfRectangleShape *content; - sfFont *font; - sfText *achievement; - sfRectangleShape *bar; - sfVector2f pos; - sfVector2f size; - int nb_achievement; - int nb_achievement_second; - } quest_t; +typedef struct { + sfRectangleShape *container; + sfRectangleShape *content; + sfFont *font; + sfText *achievement; + sfRectangleShape *bar; + sfVector2f pos; + sfVector2f size; + int nb_achievement; + int nb_achievement_second; +} quest_t; - typedef struct { - sfRectangleShape *container; - sfRectangleShape *content; - sidebar_t *sidebar; - character_t *character; - quest_t *quest; - sfFont *font; - sfText **title; - } game_menu_t; +typedef struct { + sfRectangleShape *container; + sfRectangleShape *content; + sidebar_t *sidebar; + character_t *character; + quest_t *quest; + sfFont *font; + sfText **title; +} game_menu_t; #endif /* !GAME_MENU_H_ */ diff --git a/include/inventory.h b/include/inventory.h index 8d02a70..4bc3873 100644 --- a/include/inventory.h +++ b/include/inventory.h @@ -10,16 +10,16 @@ #include "rpg.h" - typedef struct { - sfRectangleShape *container; - sfRectangleShape *content; - sfTexture *texture; - sfVector2f pos; - } item_t; +typedef struct { + sfRectangleShape *container; + sfRectangleShape *content; + sfTexture *texture; + sfVector2f pos; +} item_t; - typedef struct { - item_t **items; - int item_selected; - } inventory_t; +typedef struct { + item_t **items; + int item_selected; +} inventory_t; #endif /* !INVENTORY_H_ */ diff --git a/include/keys.h b/include/keys.h index 2a0f92e..f41b343 100644 --- a/include/keys.h +++ b/include/keys.h @@ -10,18 +10,18 @@ #include "rpg.h" - typedef struct { - sfKeyCode up; - sfKeyCode down; - sfKeyCode left; - sfKeyCode right; - sfKeyCode space; - sfKeyCode attack; - sfKeyCode inventory; - sfKeyCode pause; - sfKeyCode interact; - sfKeyCode escape; - bool switch_keys; - } keys_t; +typedef struct { + sfKeyCode up; + sfKeyCode down; + sfKeyCode left; + sfKeyCode right; + sfKeyCode space; + sfKeyCode attack; + sfKeyCode inventory; + sfKeyCode pause; + sfKeyCode interact; + sfKeyCode escape; + bool switch_keys; +} keys_t; #endif /* !KEYS_H_ */ diff --git a/include/map.h b/include/map.h index ad3f852..4ade7df 100644 --- a/include/map.h +++ b/include/map.h @@ -10,16 +10,16 @@ #include "rpg.h" - typedef struct { - sfTexture *texture; - sfSprite *sprite; - sfTexture *iso_texture; - sfSprite *iso_sprite; - sfRectangleShape *rectangle; - sfVector2f scale; - sfVector2f pos; - sfImage *colls_image; - sfIntRect rect; - } map_t; +typedef struct { + sfTexture *texture; + sfSprite *sprite; + sfTexture *iso_texture; + sfSprite *iso_sprite; + sfRectangleShape *rectangle; + sfVector2f scale; + sfVector2f pos; + sfImage *colls_image; + sfIntRect rect; +} map_t; #endif /* !MAP_H_ */ diff --git a/include/mobs.h b/include/mobs.h index 484ac24..1f1f979 100644 --- a/include/mobs.h +++ b/include/mobs.h @@ -10,29 +10,29 @@ #include "rpg.h" - enum mob_state { - Neutral = 0, - Attacking = 1, - }; +enum mob_state { + Neutral = 0, + Attacking = 1, +}; - typedef struct combat_s { - int attack; - int life; - } mob_combat_t; +typedef struct combat_s { + int attack; + int life; +} mob_combat_t; - typedef struct { - sfVector2f pos; - sfClock *clock; - sfClock *clock_anime; - enum mob_state state; - float distance_to_player; - float speed; - sfSprite *sprite; - sfIntRect TextureRect; - sfBool is_alive; - mob_combat_t *combat; - int mob_type; - int left_display; - } mobs_t; +typedef struct { + sfVector2f pos; + sfClock *clock; + sfClock *clock_anime; + enum mob_state state; + float distance_to_player; + float speed; + sfSprite *sprite; + sfIntRect TextureRect; + sfBool is_alive; + mob_combat_t *combat; + int mob_type; + int left_display; +} mobs_t; #endif /* !MOBS_H_ */ diff --git a/include/network.h b/include/network.h index d6ef01f..2213685 100644 --- a/include/network.h +++ b/include/network.h @@ -10,16 +10,16 @@ #include "rpg.h" - typedef struct { - sfVector2f pos; - sfIntRect rect; - char *name; - } client_t; +typedef struct { + sfVector2f pos; + sfIntRect rect; + char *name; +} client_t; - typedef struct { - client_t *clients; - sfTcpSocket *server; - sfSprite *client_sprite; - } network_t; +typedef struct { + client_t *clients; + sfTcpSocket *server; + sfSprite *client_sprite; +} network_t; #endif /*_NETWORK_H_*/ diff --git a/include/npc.h b/include/npc.h index 6f4b427..d9d9e47 100644 --- a/include/npc.h +++ b/include/npc.h @@ -10,23 +10,23 @@ #include "rpg.h" - enum npc_state { - None = 0, - Talking = 1, - }; +enum npc_state { + None = 0, + Talking = 1, +}; - typedef struct { - sfTexture *texture; - sfSprite *sprite; - sfVector2f pos; - sfIntRect rect; - sfClock *clock; - sfTime time; - float seconds; - char *dialog; - int dialog_index; - float distance_to_player; - enum npc_state state; - } npc_t; +typedef struct { + sfTexture *texture; + sfSprite *sprite; + sfVector2f pos; + sfIntRect rect; + sfClock *clock; + sfTime time; + float seconds; + char *dialog; + int dialog_index; + float distance_to_player; + enum npc_state state; +} npc_t; #endif /* !NPC_H_ */ diff --git a/include/overlay.h b/include/overlay.h index 8cd1b49..632a57f 100644 --- a/include/overlay.h +++ b/include/overlay.h @@ -10,18 +10,21 @@ #include "rpg.h" - typedef struct { - sfRectangleShape *container; - sfRectangleShape *content; - sfTexture *texture; - sfSprite *sprite; - sfVector2f scale; - sfVector2f pos; - sfIntRect rect; - } life_t; - - typedef struct { - life_t *life; - } overlay_t; +typedef struct { + sfRectangleShape *container; + sfRectangleShape *content; + sfTexture *texture; + sfSprite *sprite; + sfVector2f scale; + sfVector2f pos; + sfIntRect rect; +} life_t; + + +typedef struct { + + life_t *life; + +} overlay_t; #endif /* !OVERLAY_H_ */ diff --git a/include/params.h b/include/params.h index cfe63d4..849e83c 100644 --- a/include/params.h +++ b/include/params.h @@ -11,60 +11,60 @@ #include "rpg.h" #include "buttons.h" - typedef struct { - sfRectangleShape *container; - sfRectangleShape *content; - sfRectangleShape *bar; - sfVector2f pos; - sfVector2f size; - sfText *text; - buttons_t **button; - } navbar_t; +typedef struct { + sfRectangleShape *container; + sfRectangleShape *content; + sfRectangleShape *bar; + sfVector2f pos; + sfVector2f size; + sfText *text; + buttons_t **button; +} navbar_t; - typedef struct { - sfText *text; - buttons_t **button; - } fps_t; +typedef struct { + sfText *text; + buttons_t **button; +} fps_t; - typedef struct { - sfRectangleShape *container; - sfRectangleShape *content; - sfRectangleShape *bar; - sfVector2f pos; - sfVector2f size; - sfText *text; - buttons_t *button; - } music_t; +typedef struct { + sfRectangleShape *container; + sfRectangleShape *content; + sfRectangleShape *bar; + sfVector2f pos; + sfVector2f size; + sfText *text; + buttons_t *button; +} music_t; - typedef struct { - sfText *text; - buttons_t **button; - } keyboard_t; +typedef struct { + sfText *text; + buttons_t **button; +} keyboard_t; - typedef struct { - buttons_t **size; - buttons_t **resolution; - } windows_t; +typedef struct { + buttons_t **size; + buttons_t **resolution; +} windows_t; - typedef struct { - navbar_t *navbar; - fps_t *fps; - music_t *music; - keyboard_t *keyboard; - windows_t *windows; - } visu_t; +typedef struct { + navbar_t *navbar; + fps_t *fps; + music_t *music; + keyboard_t *keyboard; + windows_t *windows; +} visu_t; - typedef struct { - float volume; - float scale; - int fps; - int fullscreen; - int tmp; - bool is_fullscreen; - sfVector2u resolution; - sfVector2u window_size; - sfVideoMode mode; - visu_t * visu; - } params_t; +typedef struct { + float volume; + float scale; + int fps; + int fullscreen; + int tmp; + bool is_fullscreen; + sfVector2u resolution; + sfVector2u window_size; + sfVideoMode mode; + visu_t *visu; +} params_t; #endif /* !PARAMS_H_ */ diff --git a/include/params_fonctions.h b/include/params_fonctions.h index 0541da1..6f4424c 100644 --- a/include/params_fonctions.h +++ b/include/params_fonctions.h @@ -10,23 +10,23 @@ #include "game.h" - void set_fullscreen(game_t *game); - void set_windowed(game_t *game); - void set_1920x1080(game_t *game); - void set_1280x720(game_t *game); - void set_800x600(game_t *game); +void set_fullscreen(game_t *game); +void set_windowed(game_t *game); +void set_1920x1080(game_t *game); +void set_1280x720(game_t *game); +void set_800x600(game_t *game); - typedef struct { - void (*fonctions)(game_t *game); - } params_functions_t; +typedef struct { + void (*fonctions)(game_t *game); +} params_functions_t; - static const params_functions_t PARAMS_FLAGS[] = { - {fonctions : &set_fullscreen}, - {fonctions : &set_windowed}, - {fonctions : &set_1920x1080}, - {fonctions : &set_1280x720}, - {fonctions : &set_800x600}, - {fonctions : NULL}, - }; +static const params_functions_t PARAMS_FLAGS[] = { + {fonctions : &set_fullscreen}, + {fonctions : &set_windowed}, + {fonctions : &set_1920x1080}, + {fonctions : &set_1280x720}, + {fonctions : &set_800x600}, + {fonctions : NULL}, +}; #endif /* !PARAMS_FONCTIONS_H_ */ diff --git a/include/perso.h b/include/perso.h index 0727025..57964b8 100644 --- a/include/perso.h +++ b/include/perso.h @@ -10,28 +10,28 @@ #include "game.h" - typedef struct { - int attack; - int defense; - int life; - int strength; - int speed; - int level; - } combat_t; +typedef struct { + int attack; + int defense; + int life; + int strength; + int speed; + int level; +} combat_t; - typedef struct { - sfTexture *texture; - sfSprite *sprite; - sfVector2f pos; - sfVector2f pos_save; - sfIntRect rect; - sfClock *clock; - sfTime time; - float seconds; - int move; - int direction; - char *name; - combat_t *combat; - } perso_t; +typedef struct { + sfTexture *texture; + sfSprite *sprite; + sfVector2f pos; + sfVector2f pos_save; + sfIntRect rect; + sfClock *clock; + sfTime time; + float seconds; + int move; + int direction; + char *name; + combat_t *combat; +} perso_t; #endif /* !PERSO_H_ */ diff --git a/include/raycasting.h b/include/raycasting.h index a32d57c..c58cb0d 100644 --- a/include/raycasting.h +++ b/include/raycasting.h @@ -12,58 +12,58 @@ #define PI 3.14159265358979323846 - typedef struct { - int sprite; - sfIntRect texture_rect; - sfColor color; - sfVector2f position; - sfVector2f size; - float distance; - int x_detect; - int y_detect; - float depth; - float form_height; - float brightness; - } ray_t; +typedef struct { + int sprite; + sfIntRect texture_rect; + sfColor color; + sfVector2f position; + sfVector2f size; + float distance; + int x_detect; + int y_detect; + float depth; + float form_height; + float brightness; +} ray_t; - typedef struct { - int width; - int height; - int *map; - } raycast_map_t; +typedef struct { + int width; + int height; + int *map; +} raycast_map_t; - typedef struct { - sfVector2f position; - float direction; - float pitch; - } raycasting_player_t; +typedef struct { + sfVector2f position; + float direction; + float pitch; +} raycasting_player_t; - typedef struct { - sfVector2f position; - sfSprite *sprite; - sfIntRect dimensions; - int map; - sfTexture *texture; - double distance; - float form_height; - float depth; - float angle; - bool is_drawn; - } entity_t; +typedef struct { + sfVector2f position; + sfSprite *sprite; + sfIntRect dimensions; + int map; + sfTexture *texture; + double distance; + float form_height; + float depth; + float angle; + bool is_drawn; +} entity_t; - typedef struct { - ray_t **rays; - int fov; - int resolution; - int sensitivity; - int speed; - sfTexture **textures; - sfRectangleShape *wall_shape; - raycast_map_t *maps; - int selected_map; - raycasting_player_t *player; - int nb_rays; - entity_t **entities; - } raycasting_t; +typedef struct { + ray_t **rays; + int fov; + int resolution; + int sensitivity; + int speed; + sfTexture **textures; + sfRectangleShape *wall_shape; + raycast_map_t *maps; + int selected_map; + raycasting_player_t *player; + int nb_rays; + entity_t **entities; +} raycasting_t; #endif /*_RAYCASTING_H_*/ diff --git a/include/save.h b/include/save.h index 0d1dbbc..6be9333 100644 --- a/include/save.h +++ b/include/save.h @@ -10,15 +10,15 @@ #include "rpg.h" - typedef struct { - sfRectangleShape **rect; - sfTexture **texture; - sfText *title; - sfText **name; - } save_view_t; +typedef struct { + sfRectangleShape **rect; + sfTexture **texture; + sfText *title; + sfText **name; +} save_view_t; - typedef struct { - save_view_t *view; - } save_t; +typedef struct { + save_view_t *view; +} save_t; #endif /* !SAVE_H_ */ diff --git a/include/songs.h b/include/songs.h index 20afd37..0b4045a 100644 --- a/include/songs.h +++ b/include/songs.h @@ -10,10 +10,10 @@ #include "rpg.h" - typedef struct { - sfMusic *music; - sfSound *sound; - sfSoundBuffer *buffer; - } song_t; +typedef struct { + sfMusic *music; + sfSound *sound; + sfSoundBuffer *buffer; +} song_t; #endif /* !SONGS_H_ */ diff --git a/include/start.h b/include/start.h index 42a470a..47bb4be 100644 --- a/include/start.h +++ b/include/start.h @@ -17,9 +17,9 @@ void change_to_settings(game_t *game); typedef struct start_flags_s { void (*functions)(void *); -} start_flags; +} start_flags_t; -static const start_flags START_FLAGS[] = { +static const start_flags_t START_FLAGS[] = { {functions : (void *)&close_start_all}, {functions : (void *)&change_to_save}, {functions : (void *)&change_to_settings}, diff --git a/include/window.h b/include/window.h index af5abff..4e6b372 100644 --- a/include/window.h +++ b/include/window.h @@ -11,14 +11,14 @@ #include "rpg.h" #include "songs.h" - typedef struct window_s { - sfRenderWindow *window; - sfView *view; - sfEvent event; - sfRectangleShape **rect; - song_t *song; - int close; - const char *title; - } window_t; +typedef struct window_s { + sfRenderWindow *window; + sfView *view; + sfEvent event; + sfRectangleShape **rect; + song_t *song; + int close; + const char *title; +} window_t; #endif /* !WINDOW_H_ */ diff --git a/src/main.c b/src/main.c index be10258..0ce5a2a 100644 --- a/src/main.c +++ b/src/main.c @@ -11,7 +11,7 @@ void do_free(game_t *game); bool is_error(const char **env); int start_game(game_t *game); -network_t *connect_to_server (void); +network_t *connect_to_server(void); int main(int ac, char **av, const char **env) { @@ -19,13 +19,9 @@ int main(int ac, char **av, const char **env) (void)av; if (is_error(env)) return 84; - game_t game = {0}; - game.network = connect_to_server(); - start_game(&game); do_free(&game); - return (0); } diff --git a/src/save/save.c b/src/save/save.c index 36297d6..d7eda16 100644 --- a/src/save/save.c +++ b/src/save/save.c @@ -6,7 +6,7 @@ */ #include "game.h" -#include +#include #include "fcntl.h" #include #include diff --git a/src/save/tab_handling.c b/src/save/tab_handling.c index 111660e..815dab9 100644 --- a/src/save/tab_handling.c +++ b/src/save/tab_handling.c @@ -14,10 +14,10 @@ int my_tablen(char **tab); char *my_strdup(char *src) { + int i = 0; + char *str = NULL; if (src == NULL) return NULL; - char *str = NULL; - int i = 0; str = malloc(sizeof(char) * (my_strlen(src) + 1)); while (src[i] != '\0') { str[i] = src[i]; @@ -29,9 +29,9 @@ char *my_strdup(char *src) int free_tab(char **tab) { + int i = 0; if (tab == NULL) return 84; - int i = 0; for (; tab[i] != NULL; i++) { free(tab[i]); } diff --git a/src/save/write_save.c b/src/save/write_save.c index 243f855..ce3e33e 100644 --- a/src/save/write_save.c +++ b/src/save/write_save.c @@ -5,12 +5,12 @@ ** write_save */ -#include "game.h" -#include #include "fcntl.h" -#include -#include +#include "game.h" #include +#include +#include +#include int my_strlen(char const *str); int my_put_nbr(int valeur, int fd); int my_float(int prec, double n, int fd); diff --git a/src/start_game.c b/src/start_game.c index 4ce472e..92673d9 100644 --- a/src/start_game.c +++ b/src/start_game.c @@ -10,13 +10,15 @@ void create_game(game_t *game); void events_window(game_t *game); void display_all(game_t *game); -int raycasting (game_t *game); +int raycasting(game_t *game); static void init_game(game_t *game) { game->keys = malloc(sizeof(keys_t)); - game->keys->up = sfKeyUp; game->keys->down = sfKeyDown; - game->keys->left = sfKeyLeft; game->keys->right = sfKeyRight; + game->keys->up = sfKeyUp; + game->keys->down = sfKeyDown; + game->keys->left = sfKeyLeft; + game->keys->right = sfKeyRight; game->keys->escape = sfKeyEscape; game->keys->space = sfKeySpace; game->keys->interact = sfKeyE; @@ -47,7 +49,6 @@ int start_game(game_t *game) init_game(game); init_params(game); create_game(game); - while (sfRenderWindow_isOpen(game->window->window)) { if (game->is_raycasting == false) { events_window(game); diff --git a/src/utils/raycasting/move.c b/src/utils/raycasting/move.c index 59bdba0..ceeb393 100644 --- a/src/utils/raycasting/move.c +++ b/src/utils/raycasting/move.c @@ -9,35 +9,31 @@ #include "game.h" -static int is_colliding (game_t *game, int x, int y) +static int is_colliding(game_t *game, int x, int y) { int pos_in_map = (x + 1) / (game->params->mode.height / game->raycasting->maps[game->raycasting->selected_map].width) + (y + 1) / (game->params->mode.height / game->raycasting->maps[game->raycasting->selected_map].height) * game->raycasting->maps[game->raycasting->selected_map].width; - if (game->raycasting->maps[game->raycasting->selected_map]. map[pos_in_map] != 0) return 1; - return 0; } -static void player_move_left_right (game_t *game) +static void player_move_left_right(game_t *game) { float dir_x = cos(game->raycasting->player->direction * PI / 180) * game->raycasting->speed; float dir_y = sin(game->raycasting->player->direction * PI / 180) * game->raycasting->speed; - if (sfKeyboard_isKeyPressed(sfKeyQ) && is_colliding(game, game->raycasting-> player->position.x - dir_y, game->raycasting->player->position.y - dir_x) == 0) { game->raycasting->player->position.x -= dir_y; game->raycasting->player->position.y -= dir_x; } - if (sfKeyboard_isKeyPressed(sfKeyD) && is_colliding(game, game->raycasting-> player->position.x + dir_y, game->raycasting->player->position.y + dir_x) == 0) { @@ -46,20 +42,18 @@ static void player_move_left_right (game_t *game) } } -static void player_move_forwar_backward (game_t *game) +static void player_move_forwar_backward(game_t *game) { float dir_x = cos(game->raycasting->player->direction * PI / 180) * game->raycasting->speed; float dir_y = sin(game->raycasting->player->direction * PI / 180) * game->raycasting->speed; - if (sfKeyboard_isKeyPressed(sfKeyZ) && is_colliding(game, game->raycasting-> player->position.x + dir_x, game->raycasting->player->position.y - dir_y) == 0) { game->raycasting->player->position.x += dir_x; game->raycasting->player->position.y -= dir_y; } - if (sfKeyboard_isKeyPressed(sfKeyS) && is_colliding(game, game->raycasting-> player->position.x - dir_x, game->raycasting->player->position.y + dir_y) == 0) { @@ -68,27 +62,23 @@ static void player_move_forwar_backward (game_t *game) } } -static void player_rotate (game_t *game) +static void player_rotate(game_t *game) { if (sfKeyboard_isKeyPressed(sfKeyLeft)) game->raycasting->player->direction += game->raycasting->sensitivity; - if (sfKeyboard_isKeyPressed(sfKeyRight)) game->raycasting->player->direction -= game->raycasting->sensitivity; - if (sfKeyboard_isKeyPressed(sfKeyUp)) game->raycasting->player->pitch += game->raycasting->sensitivity * 5; - if (sfKeyboard_isKeyPressed(sfKeyDown)) game->raycasting->player->pitch -= game->raycasting->sensitivity * 5; } -void move_raycasting_player (game_t *game) +void move_raycasting_player(game_t *game) { player_rotate(game); player_move_forwar_backward(game); player_move_left_right(game); - if (sfKeyboard_isKeyPressed(sfKeyE)) { game->is_raycasting = false; game->raycasting->player->position = (sfVector2f) {500, 500}; diff --git a/src/utils/raycasting/raycasting.c b/src/utils/raycasting/raycasting.c index 1573c63..b1d8962 100644 --- a/src/utils/raycasting/raycasting.c +++ b/src/utils/raycasting/raycasting.c @@ -9,15 +9,14 @@ #include #include #include - #include "game.h" -void move_raycasting_player (game_t *game); -void get_wall (game_t *game, float i); -void sort_walls_by_distance (game_t *game); -void calculate_entity_form (game_t *game, entity_t *entity); +void move_raycasting_player(game_t *game); +void get_wall(game_t *game, float i); +void sort_walls_by_distance(game_t *game); +void calculate_entity_form(game_t *game, entity_t *entity); -void draw_entity (game_t *game, entity_t *entity) +void draw_entity(game_t *game, entity_t *entity) { calculate_entity_form(game, entity); @@ -35,30 +34,24 @@ void draw_entity (game_t *game, entity_t *entity) sfRenderWindow_drawSprite(game->window->window, entity->sprite, NULL); } -void display_wall (game_t *game, int i) +void display_wall(game_t *game, int i) { int sprite_id = game->raycasting->rays[i]->sprite - 1; - sfRectangleShape_setTexture(game->raycasting->wall_shape, game->raycasting->textures[sprite_id], 0); - sfRectangleShape_setPosition(game->raycasting->wall_shape, game->raycasting->rays[i]->position); - sfRectangleShape_setTextureRect(game->raycasting->wall_shape, game->raycasting->rays[i]->texture_rect); - sfRectangleShape_setFillColor(game->raycasting->wall_shape, game->raycasting->rays[i]->color); - sfRectangleShape_setSize(game->raycasting->wall_shape, game->raycasting->rays[i]->size); - sfRenderWindow_drawRectangleShape(game->window->window, game->raycasting->wall_shape, NULL); } -void display_scene (game_t *game, int i) +void display_scene(game_t *game, int i) { display_wall(game, i); for (int x = 0; game->raycasting->entities[x] != NULL; x++) { @@ -67,7 +60,6 @@ void display_scene (game_t *game, int i) game->raycasting->player->position.x, 2) + pow(game->raycasting->entities[x]->position.y - game->raycasting->player->position.y, 2)); - if (game->raycasting->rays[i]->distance > distance_to_player && (game->raycasting->rays[i + 1]->distance < distance_to_player || game->raycasting->rays[i + 2] == NULL) @@ -76,7 +68,7 @@ void display_scene (game_t *game, int i) } } -int raycasting (game_t *game) +int raycasting(game_t *game) { while (sfRenderWindow_pollEvent(game->window->window, &game->window->event)) if (game->window->event.type == sfEvtClosed) diff --git a/src/utils/raycasting/sort_walls.c b/src/utils/raycasting/sort_walls.c index a7a6962..60979ca 100644 --- a/src/utils/raycasting/sort_walls.c +++ b/src/utils/raycasting/sort_walls.c @@ -7,7 +7,7 @@ #include "game.h" -void swap_rays (game_t *game, int i, int j) +void swap_rays(game_t *game, int i, int j) { if (game->raycasting->rays[i]->distance > game->raycasting->rays[j]->distance) { @@ -17,7 +17,7 @@ void swap_rays (game_t *game, int i, int j) } } -void sort_walls_by_distance (game_t *game) +void sort_walls_by_distance(game_t *game) { for (int i = 0; i < game->raycasting->nb_rays - 1; i += 1) for (int j = 0; j < game->raycasting->nb_rays - 1; j += 1)