Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ clean:
rm -f $(OBJ_GAME) $(OBJ_SERVER)

fclean: clean
rm -f $(NAME) $(NAME_SERVER)
rm -f $(NAME) $(NAME_SERVER) $(NAME_CALIBRATOR)

re: fclean all

.PHONY: all clean fclean re
.PHONY: all clean fclean re
27 changes: 17 additions & 10 deletions include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@
#define BSP_MIN_SIZE 5
#define BSP_MAX_DEPTH 4
#define BSP_ROOM_MARGIN 1
#define BSP_ROOM_MIN_SIZE 6
#define BSP_ROOM_RECT_RATE 30
#define BSP_ROOM_DIAMOND_RATE 25
#define BSP_ROOM_CROSS_RATE 20
#define BSP_ROOM_BLOB_RATE 25
#define MAP_AREA 576
#define BFS_QUEUE_SIZE 576
#define MONSTER_SPEED 2.2f
#define MONSTER_AGGRO_RANGE 14.0f
#define MONSTER_AGGRO_RANGE 5.0f
#define MONSTER_WAYPOINT_REACH 0.20f
#define MONSTER_DT_MAX 0.1f
#define MONSTER_INTERCEPT 0.6f
Expand Down Expand Up @@ -91,15 +96,17 @@
#define JOYSTICK_ID 0
#define JOYSTICK_DEADZONE 18.0f
#define JOYSTICK_LOOK_SPEED 2.6f
#define JOY_BTN_A 0
#define JOY_BTN_B 1
#define JOY_BTN_X 2
#define JOY_BTN_Y 3
#define JOY_BTN_LB 4
#define JOY_BTN_RB 5
#define JOY_BTN_BACK 6
#define JOY_BTN_START 7
#define JOY_BTN_LSTICK 8
#define JOY_BTN_EQUIP 0
#define JOY_BTN_HEAL 1
#define JOY_BTN_INVENTORY 2
#define JOY_BTN_RELOAD 3
#define JOY_BTN_SLOT_PREV 4
#define JOY_BTN_SLOT_NEXT 5
#define JOY_BTN_FLASHLIGHT 6
#define JOY_BTN_SHOOT 7
#define JOY_BTN_OPTIONS 9
#define JOY_BTN_LSTICK 11
#define JOY_TRIGGER_THRESHOLD 0.45f

#define WHITE (sfColor){180, 180, 180, 255}
#define BLUE (sfColor){80, 170, 255, 255}
Expand Down
16 changes: 16 additions & 0 deletions include/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

#include "types.h"

typedef struct weapon_config_s {
wp_type_t type;
int damage;
int max_ammo;
entity_t *entity;
} weapon_config_t;

wolf_t *init_wolf(void);
void init_menu_text(wolf_t *wolf, window_t *window);
game_t *init_game(window_t *window_data);
Expand All @@ -18,8 +25,17 @@ void destroy_player(player_t *player);
void init_menu_entities(wolf_t *wolf, window_t *window);
void free_wolf(wolf_t *wolf);
void free_wolf_resources(wolf_t *wolf);
void free_game(game_t *game);
void free_player_list(list_t **list);
void free_draw_list(wolf_t *wolf, int state, int index);
void free_menu_lists(wolf_t *wolf);
void free_pause_lists(wolf_t *wolf);
void free_settings_lists(wolf_t *wolf);
void free_game_entities(wolf_t *wolf);
void init_hud(hud_t *hud, sfFont *font);
void free_hud(hud_t *hud);
window_t *create_inv(data_t *data, window_t *win, inv_t *inv);
void free_inv(inv_t *inv);
weapon_t *init_weapon(wp_type_t type, int damage,
int max_ammo, entity_t *entity);
sfRectangleShape *create_rect(sfVector2f *size,
Expand Down
17 changes: 14 additions & 3 deletions include/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ void move_player(wolf_t *wolf, player_t *player, sfEvent event,
game_t *game);
int check_collision(wall_t *wall, float x, float y);
float joystick_axis(sfJoystickAxis axis);
sfBool joystick_action_down(control_action_t action);
sfBool joystick_action_event(control_action_t action, sfEvent event);
sfBool joystick_action_down(settings_game_t *settings,
control_action_t action);
sfBool joystick_action_event(settings_game_t *settings,
control_action_t action, sfEvent event);
sfBool joystick_shoot_down(void);
sfBool joystick_menu_up(sfEvent event);
sfBool joystick_menu_down(sfEvent event);
sfBool joystick_menu_confirm(sfEvent event);
sfBool joystick_menu_left(sfEvent event);
sfBool joystick_menu_right(sfEvent event);
sfBool joystick_menu_confirm(settings_game_t *settings, sfEvent event);
int joystick_bound_button(settings_game_t *settings, control_action_t action,
int fallback);
sfBool joystick_slot_previous(settings_game_t *settings, sfEvent event);
sfBool joystick_slot_next(settings_game_t *settings, sfEvent event);
void open_inventory(wolf_t *wolf, sfEvent event, inv_t *inv);
void use_inventory_item(player_t *player, slot_t *slot);
void move_inventory_slot(wolf_t *wolf, sfEvent event, inv_t *inv);
void use_moved_inventory_slot(wolf_t *wolf, sfEvent event, inv_t *inv);
sfBool iskeypressed(int key, sfEvent event);
sfBool isactiondown(settings_game_t *settings, control_action_t action);
sfBool isactionpressed(settings_game_t *settings, control_action_t action,
Expand Down
6 changes: 6 additions & 0 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

void settings(wolf_t *wolf);
void manage_settings(wolf_t *wolf, sfEvent event);
sfBool click_controls_value(wolf_t *wolf, sfEvent event);
sfBool handle_rebind_key(wolf_t *wolf, sfEvent event);
sfBool handle_rebind_joystick(wolf_t *wolf, sfEvent event);
sfBool click_settings_triangle(wolf_t *wolf, sfEvent event);
void hover_settings_triangle(wolf_t *wolf, sfEvent event);
void apply_triangle_action(wolf_t *wolf, text_t *text, int direction);
Expand All @@ -20,9 +23,12 @@ void init_settings_buttons(wolf_t *wolf, window_t *window);
void init_audio(wolf_t *wolf, window_t *window);
void init_gameplay(wolf_t *wolf, window_t *window);
void init_controls(wolf_t *wolf, window_t *window);
void init_controller_controls(wolf_t *wolf, window_t *window);
void sync_controls_values(wolf_t *wolf, settings_game_t *settings);
void sync_controller_values(wolf_t *wolf, settings_game_t *settings);
const char *key_to_string(sfKeyCode key);
int get_control_action_by_name(const char *name);
int get_controller_action_by_name(const char *name);
sfBool is_pause_key(settings_game_t *settings, sfEvent event);
settings_game_t *init_settings_params(void);
void init_graphics_params(settings_game_t *settings, wolf_t *wolf);
Expand Down
6 changes: 6 additions & 0 deletions include/stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ void notify_player_dead(wolf_t *wolf);
void stage(wolf_t *wolf, player_t *player, sfEvent event);
void card_action(wolf_t *wolf, player_t *player, sfEvent event);
void handle_card_input(wolf_t *wolf, intermission_t *inter, sfEvent event);
int card_under_cursor(wolf_t *wolf, intermission_t *inter);
int hovered_card(intermission_t *inter);
void move_card_cursor(wolf_t *wolf);
bsp_t *bsp_new(int x, int y, int w, int h);
void bsp_free(bsp_t *node);
void bsp_split(bsp_t *node, int depth);
void carve_h(int map[MAP_HEIGHT][MAP_WIDTH], int x1, int x2, int y);
void carve_v(int map[MAP_HEIGHT][MAP_WIDTH], int y1, int y2, int x);
int bsp_room_shape_from_roll(int roll);
void bsp_carve_room_shape(bsp_t *node, int map[MAP_HEIGHT][MAP_WIDTH],
int shape);
void bsp_place_rooms(bsp_t *node, int map[MAP_HEIGHT][MAP_WIDTH]);
sfVector2i bsp_center(bsp_t *node);

Expand Down
16 changes: 16 additions & 0 deletions include/stage_card.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
** EPITECH PROJECT, 2026
** stage
** File description:
** card helpers
*/

#ifndef STAGE_CARD_H
#define STAGE_CARD_H

#include "wolf3d.h"

void card_setup_text(card_t *card, const sfFloatRect *txt);
void card_rise_single(window_t *win, card_t *card, float step);

#endif
3 changes: 3 additions & 0 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ typedef struct intermission_s {
sfClock *clock;
sfBool done;
sfBool selected;
sfBool confirm_down;
int round; /* 0 = first set, 1 = second set */
card_t card[3];
} intermission_t;
Expand Down Expand Up @@ -236,6 +237,7 @@ typedef enum {
AUDIO,
GAMEPLAY,
CONTROLS,
CONTROLLER,
ACCESSIBILITY,
} settings_t;

Expand Down Expand Up @@ -282,6 +284,7 @@ typedef struct settings_game_s {
sfBool show_minimap;
sfBool crosshair;
sfKeyCode key_bindings[CTRL_COUNT];
int joystick_bindings[CTRL_COUNT];
} settings_game_t;

typedef enum {
Expand Down
1 change: 1 addition & 0 deletions include/wolf3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "utils.h"
#include "stage.h"
#include "save.h"
#include "stage_card.h"
int program(sfRenderWindow *window, sfEvent event, wolf_t *wolf);
void network_update(wolf_t *wolf, sfClock *send_clock);
int network_is_host(wolf_t *wolf);
Expand Down
6 changes: 3 additions & 3 deletions src/check_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
static void check_game_event(sfEvent event, wolf_t *wolf)
{
if (is_pause_key(wolf->settings, event) ||
joystick_action_event(CTRL_PAUSE, event)) {
joystick_action_event(wolf->settings, CTRL_PAUSE, event)) {
wolf->menu_state = 0;
wolf->state = PAUSE;
}
Expand All @@ -31,7 +31,7 @@ static void close_inventory(wolf_t *wolf, inv_t *inv)
static void handle_escape(sfEvent event, wolf_t *wolf)
{
if (!is_pause_key(wolf->settings, event) &&
!joystick_action_event(CTRL_PAUSE, event))
!joystick_action_event(wolf->settings, CTRL_PAUSE, event))
return;
if (wolf->state == NEWGAME_MENU) {
wolf->state = MENU;
Expand All @@ -57,7 +57,7 @@ static void handle_menu_state_event(wolf_t *wolf, sfEvent event)
static void handle_game_state_event(wolf_t *wolf, sfEvent event)
{
sfBool pause = is_pause_key(wolf->settings, event) ||
joystick_action_event(CTRL_PAUSE, event);
joystick_action_event(wolf->settings, CTRL_PAUSE, event);

if (wolf->state == GAME) {
if (wolf->game->inv.open && pause)
Expand Down
6 changes: 5 additions & 1 deletion src/init/create_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ static void setup_text_data(text_t *text, text_t *data)
text_t *create_text(text_t *data,
sfFont *font, sfVector2f *pos, sfVector2f *scale)
{
text_t *text = malloc(sizeof(text_t));
text_t *text = calloc(1, sizeof(text_t));
sfFloatRect txt;

if (!text)
return NULL;
text->text = sfText_create();
if (!text->text) {
free(text);
return NULL;
}
setup_text_data(text, data);
sfText_setFont(text->text, font);
sfText_setString(text->text, data->content);
Expand Down
133 changes: 17 additions & 116 deletions src/init/free_alloc.c
Original file line number Diff line number Diff line change
@@ -1,130 +1,31 @@
/*
** EPITECH PROJECT, 2026
** menu
** wolf3d
** File description:
** menu
** cleanup entry point
*/

#include "../include/wolf3d.h"

static void free_game(game_t *game)
{
for (int i = 0; i < 2; i++)
sfClock_destroy(game->clock[i]);
free(game->wall->pixel);
sfSprite_destroy(game->wall->sprite);
sfTexture_destroy(game->wall->texture);
free(game->wall);
free(game->zbuffer);
free(game);
}

static void free_rectangles(wolf_t *wolf, int state)
{
rect_t *rect = NULL;
list_t *next = NULL;

for (list_t *curr = wolf->list[state][RECT]; curr; curr = next) {
next = curr->next;
rect = (rect_t *)curr->data;
sfRectangleShape_destroy(rect->rect);
if (rect->texture)
sfTexture_destroy(rect->texture);
if (rect->click_texture)
sfTexture_destroy(rect->click_texture);
free(rect);
free(curr);
}
}

static void free_triangle(wolf_t *wolf, int state)
{
triangle_t *triangle = NULL;
list_t *next = NULL;

for (list_t *curr = wolf->list[state][TRIANGLE]; curr; curr = next) {
next = curr->next;
triangle = (triangle_t *)curr->data;
sfConvexShape_destroy(triangle->shape);
free(triangle);
free(curr);
}
}

static void free_texts(wolf_t *wolf, int state)
{
text_t *text = NULL;
list_t *next = NULL;

for (list_t *curr = wolf->list[state][TEXT]; curr; curr = next) {
next = curr->next;
text = (text_t *)curr->data;
sfText_destroy(text->text);
free(text);
free(curr);
}
}

static void free_entities(wolf_t *wolf, int state)
{
entity_t *entity = NULL;
list_t *next = NULL;

for (list_t *curr = wolf->list[state][SPRITE]; curr; curr = next) {
next = curr->next;
entity = (entity_t *)curr->data;
sfSprite_destroy(entity->sprite);
sfTexture_destroy(entity->texture);
free(entity);
free(curr);
}
}

static void free_line(wolf_t *wolf, int state)
{
rect_t *line = NULL;
list_t *next = NULL;

for (list_t *curr = wolf->list[state][LINE]; curr; curr = next) {
next = curr->next;
line = (rect_t *)curr->data;
sfRectangleShape_destroy(line->rect);
free(line);
free(curr);
}
}

static void free_settings(wolf_t *wolf)
{
free_rectangles(wolf, SETTINGS);
free_texts(wolf, SETTINGS);
free_entities(wolf, SETTINGS);
free_line(wolf, SETTINGS);
free_triangle(wolf, SETTINGS);
}

static void free_list(wolf_t *wolf)
{
free_texts(wolf, MENU);
free_entities(wolf, MENU);
free_texts(wolf, GAME_OVER);
free_rectangles(wolf, GAME_OVER);
}
#include "../../include/wolf3d.h"

void free_wolf(wolf_t *wolf)
{
if (!wolf)
return;
if (wolf->connected)
client_close(&wolf->net);
free_wolf_resources(wolf);
destroy_player(wolf->player);
if (wolf->player)
destroy_player(wolf->player);
free_game(wolf->game);
free_list(wolf);
free_rectangles(wolf, PAUSE);
free_texts(wolf, PAUSE);
free_entities(wolf, PAUSE);
free_settings(wolf);
free(wolf->data);
free(wolf->settings);
free(wolf->tmp_settings);
free_menu_lists(wolf);
free_game_entities(wolf);
free_pause_lists(wolf);
free_settings_lists(wolf);
if (wolf->data)
free(wolf->data);
if (wolf->settings)
free(wolf->settings);
if (wolf->tmp_settings)
free(wolf->tmp_settings);
free(wolf);
}
Loading
Loading