mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
feat: finished barricades
This commit is contained in:
parent
9274a11c70
commit
7852962d56
7 changed files with 81 additions and 36 deletions
1
Makefile
1
Makefile
|
|
@ -29,6 +29,7 @@ SOURCEFILES = \
|
||||||
src/player/player.c \
|
src/player/player.c \
|
||||||
src/player/move.c \
|
src/player/move.c \
|
||||||
src/player/move_step.c \
|
src/player/move_step.c \
|
||||||
|
src/raycast/barricades.c \
|
||||||
src/raycast/ray.c \
|
src/raycast/ray.c \
|
||||||
src/raycast/walls.c \
|
src/raycast/walls.c \
|
||||||
src/renderer/render.c \
|
src/renderer/render.c \
|
||||||
|
|
|
||||||
42
src/raycast/barricades.c
Normal file
42
src/raycast/barricades.c
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* barricades.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/raycast/barricades.h
Normal file
21
src/raycast/barricades.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* barricades.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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
|
||||||
|
|
@ -6,21 +6,19 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/31 11:55:41 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 "ray.h"
|
||||||
|
#include "barricades.h"
|
||||||
#include "raycaster.h"
|
#include "raycaster.h"
|
||||||
#include "../player/player.h"
|
#include "../player/player.h"
|
||||||
#include "../consts.h"
|
#include "../consts.h"
|
||||||
#include "../sprites/create_sprite.h"
|
|
||||||
#include "../cub3d_data.h"
|
#include "../cub3d_data.h"
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "../map/collision.h"
|
#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)
|
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);
|
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)
|
void raycaster(t_cub3d_data *data, t_ray *ray)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/05 12:49:49 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
|
# define RAY_H
|
||||||
|
|
||||||
# include "../map/mapdata.h"
|
# include "../map/mapdata.h"
|
||||||
|
# define BARRICADE_TICK 55000
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* plane - plan de camera (vectoriel)
|
* plane - plan de camera (vectoriel)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/18 13:52:23 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);
|
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 *place_right_sprite(t_cub3d_data *data, char c, double x, double y)
|
||||||
{
|
{
|
||||||
t_sprite *sprite;
|
t_sprite *sprite;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/12 15:49:25 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);
|
char *filename, double x, double y);
|
||||||
t_sprite *place_right_sprite(t_cub3d_data *data, char c, double x,
|
t_sprite *place_right_sprite(t_cub3d_data *data, char c, double x,
|
||||||
double y);
|
double y);
|
||||||
|
void create_zombie(t_cub3d_data *data, double x, double y);
|
||||||
|
|
||||||
#endif // CREATE_SPRITE_H
|
#endif // CREATE_SPRITE_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue