feat: Made payable doors

This commit is contained in:
Theo Champion 2025-10-01 14:13:08 +02:00
parent 13b1f7a88c
commit 351e4bb679
7 changed files with 67 additions and 8 deletions

View file

@ -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 \

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/06 11:25:05 by kcolin #+# #+# */
/* Updated: 2025/10/01 13:43:22 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);
}

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

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> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */
/* Updated: 2025/10/01 13:50:08 by tchampio ### ########.fr */
/* Updated: 2025/10/01 14:10:46 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,7 @@
#include <math.h>
#include <stdlib.h>
#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' || data->map->map[ray->map_y][ray->map_x] == 'i') && 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;
@ -71,6 +72,8 @@ void handle_door_ray(t_ray *ray, t_cub3d_data *data)
data->keypresses.is_f_pressed = false;
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';
}

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */
/* Updated: 2025/10/01 13:36:58 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;