feat: finished payed doors

This commit is contained in:
Theo Champion 2025-10-01 17:40:07 +02:00
parent 5cc6988c9c
commit 94fd8779e2
6 changed files with 9 additions and 14 deletions

View file

@ -40,6 +40,7 @@ typedef struct s_cub3d_data
t_mapdata *map;
t_player player;
t_keypresses keypresses;
int door_amount;
int *screen_matrix;
int last_since_shoot; // temp
int delta;

View file

@ -25,7 +25,7 @@ static bool out_of_bounds(t_mapdata *data, int x, int y)
bool blocks_movement(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

@ -13,15 +13,7 @@
#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)
bool pay(t_cub3d_data *data, int amount, bool isdoor)
{
if (data->player.points < amount)
{
@ -29,5 +21,7 @@ bool pay(t_cub3d_data *data, int amount)
return (false);
}
data->player.points -= amount;
if (isdoor)
data->door_amount += 250;
return (true);
}

View file

@ -15,7 +15,6 @@
# include "../cub3d_data.h"
int door_amount(void);
bool pay(t_cub3d_data *data, int amount);
bool pay(t_cub3d_data *data, int amount, bool isdoor);
#endif // PAY_H

View file

@ -63,7 +63,7 @@ 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' || 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[1] = ray->map_y;
data->player.can_open_door = true;
@ -72,7 +72,7 @@ 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()))
else if (data->map->map[ray->map_y][ray->map_x] == 'P' && pay(data, data->door_amount, true))
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

@ -113,5 +113,6 @@ void init_cub3d_data(t_cub3d_data *data, char **argv)
load_textures(data);
data->sprite_list = ft_calloc(sizeof(t_sprite *), MAX_SPRITES);
ft_memset(data->sprite_distances, -1, MAX_SPRITES);
data->door_amount = 750;
place_base_sprites(data, data->map->map);
}