feat: Added perk buy

This commit is contained in:
Theo Champion 2025-10-03 19:05:21 +02:00
parent 55643a3d59
commit 3987a1dec1
7 changed files with 223 additions and 2439 deletions

View file

@ -17,7 +17,7 @@ bool pay(t_cub3d_data *data, int amount, bool isdoor)
{
if (data->player.points < amount)
{
ft_printf("Not enough points :(\n");
ft_printf("Not enough points >:( 🖕\n");
return (false);
}
data->player.points -= amount;

View file

@ -17,9 +17,9 @@
#include "../player/player.h"
#include "../consts.h"
#include "../cub3d_data.h"
#include <float.h>
#include <math.h>
#include "../map/collision.h"
#define FLT_EPSILON 1.19209290e-7F
void init_ray(t_ray *ray, int pos_x, t_player *player)
{

View file

@ -12,9 +12,53 @@
#include "../cub3d_data.h"
#include "../../libft/includes/libft.h"
#include "../player/pay.h"
void pick_right_perk(char symbol, t_cub3d_data *data, int *last_perk)
{
if (symbol == 'J' && !data->player.has_juggernog)
{
if (pay(data, 2500, false))
{
data->player.perk_order[(*last_perk)++] = JUGGERNOG;
data->player.has_juggernog = true;
}
}
else if (symbol == 'Q' && !data->player.has_revive)
{
if (pay(data, 1500, false))
{
data->player.perk_order[(*last_perk)++] = REVIVE;
data->player.has_revive = true;
}
}
else if (symbol == 'D' && !data->player.has_doubletap)
{
if (pay(data, 2000, false))
{
data->player.perk_order[(*last_perk)++] = DOUBLETAP;
data->player.has_doubletap = true;
}
}
}
void pay_and_give(t_cub3d_data *data, t_sprite *current_sprite)
{
static int last_perk_pos = 0;
char symbol;
if (last_perk_pos > 2)
return ;
symbol = data->map->map[(int)current_sprite->y][(int)current_sprite->x];
pick_right_perk(symbol, data, &last_perk_pos);
}
void handle_sprite_interactions(t_cub3d_data *data)
{
t_sprite *current_sprite;
current_sprite = data->sprite_list
[data->sprite_order[data->sprite_counter - 1]];
if (data->sprite_distances[data->sprite_counter - 1] <= 1.5)
{
if (data->sprite_list[data->sprite_order[data->sprite_counter - 1]]
@ -23,7 +67,7 @@ void handle_sprite_interactions(t_cub3d_data *data)
if (data->keypresses.is_f_pressed)
{
data->keypresses.is_f_pressed = false;
ft_printf("🎵You need a little revive🎵\n");
pay_and_give(data, current_sprite);
}
}
}