From 7852962d564c24595ce265e4e2e5680be6d05602 Mon Sep 17 00:00:00 2001 From: Theo Champion Date: Tue, 9 Sep 2025 14:09:20 +0200 Subject: [PATCH] feat: finished barricades --- Makefile | 1 + src/raycast/barricades.c | 42 +++++++++++++++++++++++++++++++++++++ src/raycast/barricades.h | 21 +++++++++++++++++++ src/raycast/ray.c | 35 ++----------------------------- src/raycast/ray.h | 3 ++- src/sprites/create_sprite.c | 12 ++++++++++- src/sprites/create_sprite.h | 3 ++- 7 files changed, 81 insertions(+), 36 deletions(-) create mode 100644 src/raycast/barricades.c create mode 100644 src/raycast/barricades.h diff --git a/Makefile b/Makefile index d28974d..59a0922 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ SOURCEFILES = \ src/player/player.c \ src/player/move.c \ src/player/move_step.c \ + src/raycast/barricades.c \ src/raycast/ray.c \ src/raycast/walls.c \ src/renderer/render.c \ diff --git a/src/raycast/barricades.c b/src/raycast/barricades.c new file mode 100644 index 0000000..1e0febe --- /dev/null +++ b/src/raycast/barricades.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* barricades.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/09 14:00:36 by tchampio #+# #+# */ +/* Updated: 2025/09/09 14:04:01 by tchampio ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ray.h" +#include "../cub3d_data.h" +#include "../sprites/create_sprite.h" + +void check_barricades(t_ray *ray, t_cub3d_data *data) +{ + static int last_barricade_y; + static int last_barricade_x; + static int remaining_ticks = BARRICADE_TICK; + + if (data->map->map[ray->map_y][ray->map_x] >= '2' + && data->map->map[ray->map_y][ray->map_x] <= '8') + { + if (last_barricade_x != ray->map_x || last_barricade_y != ray->map_y) + { + last_barricade_x = ray->map_x; + last_barricade_y = ray->map_y; + remaining_ticks = BARRICADE_TICK; + } + remaining_ticks--; + if (remaining_ticks <= 0) + { + remaining_ticks = BARRICADE_TICK; + if (data->map->map[last_barricade_y][last_barricade_x] < '8') + data->map->map[last_barricade_y][last_barricade_x]++; + if (data->map->map[last_barricade_y][last_barricade_x] == '8') + create_zombie(data, last_barricade_x, last_barricade_y); + } + } +} diff --git a/src/raycast/barricades.h b/src/raycast/barricades.h new file mode 100644 index 0000000..4c01f00 --- /dev/null +++ b/src/raycast/barricades.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* barricades.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/09 14:01:49 by tchampio #+# #+# */ +/* Updated: 2025/09/09 14:02:33 by tchampio ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef BARRICADES_H +# define BARRICADES_H + +# include "../cub3d_data.h" +# include "ray.h" + +void check_barricades(t_ray *ray, t_cub3d_data *data); + +#endif // BARRICADES_H diff --git a/src/raycast/ray.c b/src/raycast/ray.c index 478d7e0..bcbfb7c 100644 --- a/src/raycast/ray.c +++ b/src/raycast/ray.c @@ -6,21 +6,19 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */ -/* Updated: 2025/09/09 11:51:54 by tchampio ### ########.fr */ +/* Updated: 2025/09/09 14:07:24 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ #include "ray.h" +#include "barricades.h" #include "raycaster.h" #include "../player/player.h" #include "../consts.h" -#include "../sprites/create_sprite.h" #include "../cub3d_data.h" #include #include #include "../map/collision.h" -#include "../../libft/includes/libft.h" -#define BARRICADE_TICK 55000 void init_ray(t_ray *ray, int pos_x, t_player *player) { @@ -100,35 +98,6 @@ void calculate_wall_height(t_ray *ray, t_player *player) ray->wall_x -= floor(ray->wall_x); } -void check_barricades(t_ray *ray, t_cub3d_data *data) -{ - static int last_barricade_y; - static int last_barricade_x; - static int remaining_ticks = BARRICADE_TICK; - - if (ft_strchr("2345678", data->map->map[ray->map_y][ray->map_x])) - { - if (last_barricade_x != ray->map_x || last_barricade_y != ray->map_y) - { - last_barricade_x = ray->map_x; - last_barricade_y = ray->map_y; - remaining_ticks = BARRICADE_TICK; - ft_printf("Changed barricade focus\n"); - } - //ft_printf("Remaining ticks before destroying %d\n", remaining_ticks); - remaining_ticks--; - if (remaining_ticks <= 0) - { - remaining_ticks = BARRICADE_TICK; - if (data->map->map[last_barricade_y][last_barricade_x] < '8') - data->map->map[last_barricade_y][last_barricade_x]++; - if (data->map->map[last_barricade_y][last_barricade_x] == '8') - ft_printf("Spawning zombie. Boo it's so scary\n"); - ft_printf("Barricade is now at level %d\n", data->map->map[last_barricade_y][last_barricade_x] - '0'); - } - } -} - void raycaster(t_cub3d_data *data, t_ray *ray) { int x; diff --git a/src/raycast/ray.h b/src/raycast/ray.h index 3f5199b..02f5180 100644 --- a/src/raycast/ray.h +++ b/src/raycast/ray.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/08/05 12:49:49 by kcolin #+# #+# */ -/* Updated: 2025/08/05 12:49:49 by kcolin ### ########.fr */ +/* Updated: 2025/09/09 14:01:28 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ # define RAY_H # include "../map/mapdata.h" +# define BARRICADE_TICK 55000 /* * plane - plan de camera (vectoriel) diff --git a/src/sprites/create_sprite.c b/src/sprites/create_sprite.c index 987d484..a017cdb 100644 --- a/src/sprites/create_sprite.c +++ b/src/sprites/create_sprite.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/08/18 13:52:23 by kcolin #+# #+# */ -/* Updated: 2025/08/18 19:19:53 by tchampio ### ########.fr */ +/* Updated: 2025/09/09 14:08:10 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,16 @@ t_sprite *create_sprite(t_cub3d_data *data, char *texture, return (sprite); } +void create_zombie(t_cub3d_data *data, double x, double y) +{ + if (data->sprite_counter > MAX_SPRITES - 1) + return ; + data->sprite_list[data->sprite_counter] = create_sprite(data, + "ressources/zombie.xpm", x, y); + data->sprite_list[data->sprite_counter]->sprite_type = ZOMBIE; + data->sprite_counter++; +} + t_sprite *place_right_sprite(t_cub3d_data *data, char c, double x, double y) { t_sprite *sprite; diff --git a/src/sprites/create_sprite.h b/src/sprites/create_sprite.h index fe204ee..26b2479 100644 --- a/src/sprites/create_sprite.h +++ b/src/sprites/create_sprite.h @@ -6,7 +6,7 @@ /* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/08/12 15:49:25 by tchampio #+# #+# */ -/* Updated: 2025/08/12 16:13:02 by tchampio ### ########.fr */ +/* Updated: 2025/09/09 13:30:02 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,5 +19,6 @@ t_sprite *create_sprite(t_cub3d_data *data, char *filename, double x, double y); t_sprite *place_right_sprite(t_cub3d_data *data, char c, double x, double y); +void create_zombie(t_cub3d_data *data, double x, double y); #endif // CREATE_SPRITE_H