Compare commits

...

3 commits

Author SHA1 Message Date
Theo Champion
351e4bb679 feat: Made payable doors 2025-10-01 14:13:20 +02:00
Theo Champion
13b1f7a88c fix: Fixed memory leak for the door texture 2025-10-01 13:58:19 +02:00
Theo Champion
47ffb17047 feat: Made doors opening and closing 2025-10-01 13:53:02 +02:00
10 changed files with 77 additions and 12 deletions

View file

@ -31,6 +31,7 @@ SOURCEFILES = \
src/player/move_step.c \ src/player/move_step.c \
src/player/register_weapons.c \ src/player/register_weapons.c \
src/player/weapons.c \ src/player/weapons.c \
src/player/pay.c \
src/raycast/barricades.c \ src/raycast/barricades.c \
src/raycast/ray.c \ src/raycast/ray.c \
src/raycast/walls.c \ src/raycast/walls.c \

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */ /* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
/* Updated: 2025/09/30 17:32:50 by tchampio ### ########.fr */ /* Updated: 2025/10/01 13:50:59 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */ /* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/03 17:02:08 by tchampio #+# #+# */ /* Created: 2025/09/03 17:02:08 by tchampio #+# #+# */
/* Updated: 2025/09/30 17:35:31 by tchampio ### ########.fr */ /* Updated: 2025/10/01 13:51:03 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/06 11:25:05 by kcolin #+# #+# */ /* Created: 2025/08/06 11:25:05 by kcolin #+# #+# */
/* Updated: 2025/09/30 17:43:36 by tchampio ### ########.fr */ /* Updated: 2025/10/01 14:11:11 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,7 +32,7 @@ bool blocks_movement(t_mapdata *data, int x, int y)
bool blocks_view(t_mapdata *data, int x, int y) bool blocks_view(t_mapdata *data, int x, int y)
{ {
if (out_of_bounds(data, x, y) || ft_strchr("12345678d", data->map[y][x])) if (out_of_bounds(data, x, y) || ft_strchr("12345678dP", data->map[y][x]))
return (true); return (true);
return (false); return (false);
} }

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:18:13 by kcolin #+# #+# */ /* Created: 2025/07/17 14:18:13 by kcolin #+# #+# */
/* Updated: 2025/09/30 17:23:06 by tchampio ### ########.fr */ /* Updated: 2025/10/01 14:08:45 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,10 +24,11 @@
* z - beware of zombies * z - beware of zombies
* d - closed door * d - closed door
* i - open dooro * i - open dooro
* P - payable door
*/ */
bool has_forbidden_characters(char *line) bool has_forbidden_characters(char *line)
{ {
static const char *allowedchars = " 10234567NSEWMQJDzdi\n"; static const char *allowedchars = " 10234567NSEWMQJDzdiP\n";
size_t strsize; size_t strsize;
int i; int i;

33
src/player/pay.c Normal file
View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* door.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/01 13:59:11 by tchampio #+# #+# */
/* Updated: 2025/10/01 14:05:57 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d_data.h"
#include "../../libft/includes/libft.h"
int door_amount(void)
{
static int amount = 500;
amount += 250;
return (amount);
}
bool pay(t_cub3d_data *data, int amount)
{
if (data->player.points < amount)
{
ft_printf("Not enough points :(\n");
return (false);
}
data->player.points -= amount;
return (true);
}

21
src/player/pay.h Normal file
View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pay.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/01 14:05:08 by tchampio #+# #+# */
/* Updated: 2025/10/01 14:06:19 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PAY_H
# define PAY_H
# include "../cub3d_data.h"
int door_amount(void);
bool pay(t_cub3d_data *data, int amount);
#endif // PAY_H

View file

@ -6,7 +6,7 @@
/* 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/30 23:05:11 by tchampio ### ########.fr */ /* Updated: 2025/10/01 14:10:46 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,6 +21,7 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include "../map/collision.h" #include "../map/collision.h"
#include "../player/pay.h"
#include "../../libft/includes/libft.h" #include "../../libft/includes/libft.h"
void init_ray(t_ray *ray, int pos_x, t_player *player) void init_ray(t_ray *ray, int pos_x, t_player *player)
@ -60,7 +61,7 @@ void ray_calculate_step(t_ray *ray, t_player *player)
void handle_door_ray(t_ray *ray, t_cub3d_data *data) void handle_door_ray(t_ray *ray, t_cub3d_data *data)
{ {
if (data->map->map[ray->map_y][ray->map_x] == 'd' && ray->wall_dist < 1.5) if ((data->map->map[ray->map_y][ray->map_x] == 'd' || data->map->map[ray->map_y][ray->map_x] == 'i' || data->map->map[ray->map_y][ray->map_x] == 'P') && ray->wall_dist < 1.5)
{ {
ft_printf("map[%d][%d] = door reachable\n", ray->map_y, ray->map_x); ft_printf("map[%d][%d] = door reachable\n", ray->map_y, ray->map_x);
data->player.closest_door[0] = ray->map_x; data->player.closest_door[0] = ray->map_x;
@ -69,7 +70,12 @@ void handle_door_ray(t_ray *ray, t_cub3d_data *data)
if (data->keypresses.is_f_pressed) if (data->keypresses.is_f_pressed)
{ {
data->keypresses.is_f_pressed = false; data->keypresses.is_f_pressed = false;
data->map->map[ray->map_y][ray->map_x] = 'i'; if (data->map->map[ray->map_y][ray->map_x] == 'd')
data->map->map[ray->map_y][ray->map_x] = 'i';
else if (data->map->map[ray->map_y][ray->map_x] == 'P' && pay(data, door_amount()))
data->map->map[ray->map_y][ray->map_x] = '0';
else if (data->map->map[ray->map_y][ray->map_x] == 'i')
data->map->map[ray->map_y][ray->map_x] = 'd';
} }
} }
else else
@ -86,6 +92,8 @@ void calculate_wall_dist(t_ray *ray, int x, t_cub3d_data *data)
{ {
if (x == WIDTH / 2) if (x == WIDTH / 2)
check_for_zombies(ray, data); check_for_zombies(ray, data);
if (!blocks_view(data->map, ray->map_x, ray->map_y) && data->map->map[ray->map_y][ray->map_x] == 'i')
handle_door_ray(ray, data);
if (ray->side_dist_x < ray->side_dist_y) if (ray->side_dist_x < ray->side_dist_y)
{ {
ray->side_dist_x += ray->delta_dist_x; ray->side_dist_x += ray->delta_dist_x;

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */ /* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */
/* Updated: 2025/09/30 17:41:52 by tchampio ### ########.fr */ /* Updated: 2025/10/01 14:12:44 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -66,7 +66,7 @@ static int get_color(t_cub3d_data *data, t_ray *ray, int tex_y)
if (ft_strchr("234567", data->map->map[ray->map_y][ray->map_x])) if (ft_strchr("234567", data->map->map[ray->map_y][ray->map_x]))
return (my_mlx_pixel_get(get_right_barricade(data, return (my_mlx_pixel_get(get_right_barricade(data,
data->map->map[ray->map_y][ray->map_x]), tex_x, tex_y)); data->map->map[ray->map_y][ray->map_x]), tex_x, tex_y));
if (data->map->map[ray->map_y][ray->map_x] == 'd') if (data->map->map[ray->map_y][ray->map_x] == 'd' || data->map->map[ray->map_y][ray->map_x] == 'P')
return (my_mlx_pixel_get(data->door_texture, tex_x, tex_y)); return (my_mlx_pixel_get(data->door_texture, tex_x, tex_y));
if (dir == NORTH) if (dir == NORTH)
texture = data->no_texture; texture = data->no_texture;

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */ /* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */
/* Updated: 2025/09/22 17:18:55 by tchampio ### ########.fr */ /* Updated: 2025/10/01 13:57:48 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -43,6 +43,7 @@ void destroy_textures(t_cub3d_data *data)
i = 0; i = 0;
while (i < 6) while (i < 6)
destroy_texture(data, data->barricades_texture[i++]); destroy_texture(data, data->barricades_texture[i++]);
destroy_texture(data, data->door_texture);
} }
void destroy_sprites(t_cub3d_data *data) void destroy_sprites(t_cub3d_data *data)