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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ GAME_FILES = ceiling.c \
draw.c \
enemy.c \
event.c \
call_to_event.c \
floor.c \
fps.c \
map.c \
Expand Down
38 changes: 19 additions & 19 deletions include/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
*/

#ifndef MACRO_H
#define MACRO_H
#include <SFML/Graphics.h>
#define MACRO_H
#include <SFML/Graphics.h>

/* TITLE */
#define TITLE "Your local low cost Wolfenstein 3D from 1992 ultimate"
#define TITLE "Your local low cost Wolfenstein 3D from 1992 ultimate"

/* SCREEN */
#define WIDTH 1920
#define HEIGHT 1080
#define WIDTH 1920
#define HEIGHT 1080

/* FONT */
#define FONT sfFont_createFromFile("assets/fonts/deathshead.otf")
#define FONT2 sfFont_createFromFile("assets/fonts/fira.ttf")
#define FONT sfFont_createFromFile("assets/fonts/deathshead.otf")
#define FONT2 sfFont_createFromFile("assets/fonts/fira.ttf")

/* Colors */
#define BLACK sfColor_fromRGB(10, 10, 10)
#define GREY sfColor_fromRGB(50, 50, 50)
#define RED sfColor_fromRGB(100, 20, 30)
#define GREEN sfColor_fromRGB(20, 100, 20)
#define BLUE sfColor_fromRGB(20, 20, 100)
#define WHITE sfColor_fromRGB(220, 220, 220)
#define BLACK sfColor_fromRGB(10, 10, 10)
#define GREY sfColor_fromRGB(50, 50, 50)
#define RED sfColor_fromRGB(100, 20, 30)
#define GREEN sfColor_fromRGB(20, 100, 20)
#define BLUE sfColor_fromRGB(20, 20, 100)
#define WHITE sfColor_fromRGB(220, 220, 220)

/* PI */
#define PI 3.1415926535
#define P2 PI / 2
#define P3 3 * PI / 2
#define PI 3.1415926535
#define P2 PI / 2
#define P3 3 * PI / 2

/* RADIANS */
#define RAD 0.0174533
#define DEG_TO_RAD(a) (a * PI / 180.0)
#define RAD 0.0174533
#define DEG_TO_RAD(a) (a * PI / 180.0)

#endif /* MACRO_H */
#endif /* MACRO_H */
16 changes: 10 additions & 6 deletions include/my.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#ifndef MY
#define MY

/* Mandatory */
#include <unistd.h>
#include <stdlib.h>
/* Mandatory */
#include "struct.h"
#include <stdlib.h>
#include <unistd.h>

/* CSFML */
/* CSFML */
#include <SFML/System.h>
#include <SFML/Window.h>

Expand Down Expand Up @@ -46,6 +46,7 @@ void change_screen_mode(data_t *data);
void draw_ceiling(data_t *data);

/* draw.c */
void draw_rays(data_t *data);
void draw(data_t *data);

/* ennemy.c */
Expand All @@ -58,6 +59,9 @@ void destroy_enemy(enemy_t *enemy);
size_t init_keys(data_t *data);
void event(data_t *data);

/* call_to_event */
void call_to_event(data_t *data, sfEvent event);

/* floor.c */
void draw_floor(data_t *data);

Expand All @@ -68,6 +72,7 @@ void draw_fps(sfRenderWindow *win, double fps);
size_t init_map(data_t *data);

/* player.c */
void draw_player(data_t *data);
size_t init_player(data_t *data);

size_t weapon(data_t *data);
Expand All @@ -84,8 +89,7 @@ button_anim_t *create_button_anim(void);
void destroy_button_anim(button_anim_t *anim);
void start_button_animation(button_t *button);
void update_button_animation(button_t *button, float dtime);
void check_button_clicks(data_t *data, sfVector2i mouse_pos,
menu_t *menu);
void check_button_clicks(data_t *data, sfVector2i mouse_pos, menu_t *menu);
void handle_button_click(button_t *button, sfVector2i mouse_pos,
sfRenderWindow *win, sfBool *action);

Expand Down
26 changes: 26 additions & 0 deletions src/wolf/game/call_to_event.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
** EPITECH PROJECT, 2025
** Wolf3D
** File description:
** call_to_event
*/

#include "my.h"

void call_to_event(data_t *data, sfEvent event)
{
static size_t status = 0;

if (!data)
return;
if (event.type == sfEvtClosed)
sfRenderWindow_close(data->win);
if (sfKeyboard_isKeyPressed(sfKeyEscape))
data->scenes = PAUSE;
if (sfKeyboard_isKeyPressed(sfKeyL) && !status) {
data->flash *= -1;
status = 1;
}
if (event.type == sfEvtKeyReleased)
status = 0;
}
15 changes: 3 additions & 12 deletions src/wolf/game/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static size_t flashlight(data_t *data, sfVector2i i, sfVector2f line)
{
if (data->flash < 0)
return EXIT_SUCCESS;
if (i.x > 30 && i.x < 60 &&
if (i.x > (int)data->FOV / 3 && i.x < (int)(data->FOV / 3) * 2 &&
line.x / 5 < i.y && line.x * 4 / 5 > i.y)
return EXIT_FAILURE;
return EXIT_SUCCESS;
Expand All @@ -44,7 +44,7 @@ static void create_rectangle(data_t *data, sfColor color,
i.y * 1.5 + line.y});
sfRectangleShape_setSize(wall, (sfVector2f){MAP_S, MAP_S});
if (flashlight(data, i, line))
color = sfColor_add(color, (sfColor){40, 40, 40, 0};
color = sfColor_add(color, (sfColor){40, 40, 40, 0});
sfRectangleShape_setFillColor(wall, color);
sfRenderWindow_drawRectangleShape(data->win, wall, NULL);
sfRectangleShape_destroy(wall);
Expand Down Expand Up @@ -115,7 +115,7 @@ static void draw_varray(data_t *data, int *shade)
sfVertexArray_destroy(ray);
}

static void draw_rays(data_t *data)
void draw_rays(data_t *data)
{
int shade = 0;

Expand All @@ -131,15 +131,6 @@ static void draw_rays(data_t *data)
}
}

static void draw_player(data_t *data)
{
sfVector2f pos = {data->p->pos.x - 3, data->p->pos.y - 3};

sfRectangleShape_setPosition(data->p->texture, pos);
sfRenderWindow_drawRectangleShape(data->win, data->p->texture, NULL);
draw_rays(data);
}

static void draw_map(data_t *data)
{
sfRectangleShape *tile = {0};
Expand Down
38 changes: 15 additions & 23 deletions src/wolf/game/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
** event.c
*/

#include "my.h"
#include "macro.h"
#include "my.h"
#include <SFML/Window/Event.h>
#include <math.h>

Expand Down Expand Up @@ -53,8 +53,8 @@ static void forward_backward(data_t *data)
if (data->keys->z) {
if (data->map->map[data->p->ip.y][data->p->ippo.x] == 0)
data->p->pos.x += cos(data->p->angle) * dtime;
if (data->map->map[data->p->ippo.y][data->p->ip.x] == 0)
data->p->pos.y += sin(data->p->angle) * dtime;
if (data->map->map[data->p->ippo.y][data->p->ip.x] == 0)
data->p->pos.y += sin(data->p->angle) * dtime;
}
if (data->keys->s) {
if (data->map->map[data->p->ip.y][data->p->ipmo.x] == 0)
Expand Down Expand Up @@ -119,10 +119,10 @@ static void check_walls_lr(data_t *data)
if (sin(data->p->angle + 90 * RAD) < 0)
o.y = -8;
o.y += 4;
data->p->jppo = (sfVector2i){(p.x + o.x) / (float)MAP_S,
(p.y + o.y) / (float)MAP_S};
data->p->jpmo = (sfVector2i){(p.x - o.x) / (float)MAP_S,
(p.y - o.y) / (float)MAP_S};
data->p->jppo =
(sfVector2i){(p.x + o.x) / (float)MAP_S, (p.y + o.y) / (float)MAP_S};
data->p->jpmo =
(sfVector2i){(p.x - o.x) / (float)MAP_S, (p.y - o.y) / (float)MAP_S};
}

static void check_walls(data_t *data)
Expand All @@ -137,36 +137,28 @@ static void check_walls(data_t *data)
if (sin(data->p->angle) < 0)
o.y = -8;
o.y += 4;
data->p->ippo = (sfVector2i){(p.x + o.x) / (float)MAP_S,
(p.y + o.y) / (float)MAP_S};
data->p->ipmo = (sfVector2i){(p.x - o.x) / (float)MAP_S,
(p.y - o.y) / (float)MAP_S};
data->p->ippo =
(sfVector2i){(p.x + o.x) / (float)MAP_S, (p.y + o.y) / (float)MAP_S};
data->p->ipmo =
(sfVector2i){(p.x - o.x) / (float)MAP_S, (p.y - o.y) / (float)MAP_S};
check_walls_lr(data);
}

void event(data_t *data)
{
sfEvent event = {.type = sfEvtKeyPressed};
static size_t status = 0;

if (!data)
return;
sfRenderWindow_pollEvent(data->win, &event);
if (event.type == sfEvtClosed)
sfRenderWindow_close(data->win);
if (sfKeyboard_isKeyPressed(sfKeyEscape))
data->scenes = PAUSE;
update_keys(data, event);
if (sfKeyboard_isKeyPressed(sfKeyL) && !status){
data->flash *= -1;
status = 1;
}
if (event.type == sfEvtKeyReleased)
status = 0;
check_walls(data);
update_movement(data);
update_camera(data);
update_enemy(data);
call_to_event(data, event);
if (data->keys->space == 1 &&
is_hit(data->e, data->p->pos, data->p->angle)) {
is_hit(data->e, data->p->pos, data->p->angle)) {
data->e->health -= 10;
data->keys->space++;
if (data->e->health <= 0)
Expand Down
9 changes: 9 additions & 0 deletions src/wolf/game/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
#include "my.h"
#include "macro.h"

void draw_player(data_t *data)
{
sfVector2f pos = {data->p->pos.x - 3, data->p->pos.y - 3};

sfRectangleShape_setPosition(data->p->texture, pos);
sfRenderWindow_drawRectangleShape(data->win, data->p->texture, NULL);
draw_rays(data);
}

size_t init_player(data_t *data)
{
data->p = malloc(sizeof(player_t));
Expand Down
14 changes: 7 additions & 7 deletions src/wolf/game/weapon.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ static void init_rect(data_t *data)
sfVector2u img_size = sfImage_getSize(image);

if (!data)
return;
data->w[data->wnb]->idle_rect =
(sfIntRect){0, 0, img_size.x, img_size.y / 3};
return;
data->w[data->wnb]->idle_rect = (sfIntRect){0, 0, img_size.x,
img_size.y / 3};
data->w[data->wnb]->shoot_rect =
(sfIntRect){0, img_size.y / 3, img_size.x, (img_size.y / 3)};
(sfIntRect){0, img_size.y / 3, img_size.x, (img_size.y / 3)};
data->w[data->wnb]->recoil_rect =
(sfIntRect){0, (img_size.y / 3) * 2, img_size.x, img_size.y};
(sfIntRect){0, (img_size.y / 3) * 2, img_size.x, img_size.y};
sfImage_destroy(image);
}

Expand All @@ -37,15 +37,15 @@ static void load_weapon(data_t *data)
sfTexture_createFromFile("assets/img/weap_rec.png", NULL);
data->w[data->wnb]->sprite->size = (sfVector2f){132, 416};
data->w[data->wnb]->sprite->pos =
(sfVector2f){WIDTH / 2 - 115, HEIGHT / 2 + 30};
(sfVector2f){WIDTH / 2 - 115, HEIGHT / 2 + 25};
sfSprite_setTexture(data->w[data->wnb]->sprite->s,
data->w[data->wnb]->sprite->t, sfTrue);
init_rect(data);
sfSprite_setTextureRect(data->w[data->wnb]->sprite->s,
data->w[data->wnb]->idle_rect);
sfSprite_setPosition(data->w[data->wnb]->sprite->s,
data->w[data->wnb]->sprite->pos);
sfSprite_setScale(data->w[data->wnb]->sprite->s, (sfVector2f){1.2, 1.2});
sfSprite_setScale(data->w[data->wnb]->sprite->s, (sfVector2f){1.8, 1.8});
}

static void init_weapon(data_t *data)
Expand Down