diff --git a/Makefile b/Makefile index 1e300ee..7e97e96 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ SOURCEFILES = \ src/player/move_step.c \ src/player/register_weapons.c \ src/player/weapons.c \ + src/player/pay.c \ src/raycast/barricades.c \ src/raycast/ray.c \ src/raycast/walls.c \ diff --git a/src/cub3d_data.h b/src/cub3d_data.h index 4e8553f..43d1389 100644 --- a/src/cub3d_data.h +++ b/src/cub3d_data.h @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/src/hud/load_texture.c b/src/hud/load_texture.c index 1aca228..b8fbb02 100644 --- a/src/hud/load_texture.c +++ b/src/hud/load_texture.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/src/map/collision.c b/src/map/collision.c index 8add28c..fbc2335 100644 --- a/src/map/collision.c +++ b/src/map/collision.c @@ -6,7 +6,7 @@ /* 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) { - 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 (false); } diff --git a/src/map/forbidden_characters.c b/src/map/forbidden_characters.c index 0ff4054..371f547 100644 --- a/src/map/forbidden_characters.c +++ b/src/map/forbidden_characters.c @@ -6,7 +6,7 @@ /* 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 * d - closed door * i - open dooro +* P - payable door */ bool has_forbidden_characters(char *line) { - static const char *allowedchars = " 10234567NSEWMQJDzdi\n"; + static const char *allowedchars = " 10234567NSEWMQJDzdiP\n"; size_t strsize; int i; diff --git a/src/player/pay.c b/src/player/pay.c new file mode 100644 index 0000000..0d4f1a7 --- /dev/null +++ b/src/player/pay.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* door.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/src/player/pay.h b/src/player/pay.h new file mode 100644 index 0000000..f656239 --- /dev/null +++ b/src/player/pay.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pay.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 diff --git a/src/raycast/ray.c b/src/raycast/ray.c index d98e552..04b42b6 100644 --- a/src/raycast/ray.c +++ b/src/raycast/ray.c @@ -6,7 +6,7 @@ /* 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 #include #include "../map/collision.h" +#include "../player/pay.h" #include "../../libft/includes/libft.h" 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) { - 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); 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) { 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 @@ -86,6 +92,8 @@ void calculate_wall_dist(t_ray *ray, int x, t_cub3d_data *data) { if (x == WIDTH / 2) 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) { ray->side_dist_x += ray->delta_dist_x; diff --git a/src/raycast/walls.c b/src/raycast/walls.c index c653c77..2b27a86 100644 --- a/src/raycast/walls.c +++ b/src/raycast/walls.c @@ -6,7 +6,7 @@ /* 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])) return (my_mlx_pixel_get(get_right_barricade(data, 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)); if (dir == NORTH) texture = data->no_texture; diff --git a/src/utils/destroy_utils.c b/src/utils/destroy_utils.c index f2ae913..dc556b5 100644 --- a/src/utils/destroy_utils.c +++ b/src/utils/destroy_utils.c @@ -6,7 +6,7 @@ /* 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; while (i < 6) destroy_texture(data, data->barricades_texture[i++]); + destroy_texture(data, data->door_texture); } void destroy_sprites(t_cub3d_data *data)