feat: Made a little sprite interaction for perk type sprites

It's more for the sake of the demo but it shows we can make interactions
with sprites. Although it's badly integrated.
This commit is contained in:
Theo Champion 2025-08-13 15:31:40 +02:00
parent ee329812fd
commit 01f0ac21df
4 changed files with 21 additions and 5 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
/* Updated: 2025/07/29 13:28:08 by tchampio ### ########.fr */
/* Updated: 2025/08/13 15:31:17 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/05 15:51:01 by tchampio #+# #+# */
/* Updated: 2025/08/07 16:57:29 by tchampio ### ########.fr */
/* Updated: 2025/08/13 15:30:55 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,8 +15,8 @@
#include "../renderer/render.h"
#include "sort_sprites.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "../../libft/includes/libft.h"
static void calculate_pos_and_transform(t_cub3d_data *data, t_sprite *sprite,
int i)
@ -109,6 +109,17 @@ void sprite_caster(t_cub3d_data *data)
if (!data->sprite_list)
return ;
sort_sprites(data->sprite_order, data->sprite_distances, data);
if (data->sprite_distances[3] <= 1.5)
{
if (data->sprite_list[data->sprite_order[3]]->sprite_type == PERK)
{
if (data->keypresses.is_f_pressed)
{
data->keypresses.is_f_pressed = false;
ft_printf("🎵You need a little revive🎵\n");
}
}
}
i = 0;
while (data->sprite_list[i] && i < MAX_SPRITES)
{

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:22:57 by kcolin #+# #+# */
/* Updated: 2025/07/29 13:35:29 by tchampio ### ########.fr */
/* Updated: 2025/08/13 15:25:04 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,6 +31,8 @@ int keypress_handler(int keycode, t_cub3d_data *data)
data->keypresses.is_s_pressed = true;
if (keycode == XK_d)
data->keypresses.is_d_pressed = true;
if (keycode == XK_f)
data->keypresses.is_f_pressed = true;
if (keycode == XK_Left)
data->keypresses.is_left_pressed = true;
if (keycode == XK_Right)
@ -48,6 +50,8 @@ int keyrelease_handler(int keycode, t_cub3d_data *data)
data->keypresses.is_s_pressed = false;
if (keycode == XK_d)
data->keypresses.is_d_pressed = false;
if (keycode == XK_f)
data->keypresses.is_f_pressed = false;
if (keycode == XK_Left)
data->keypresses.is_left_pressed = false;
if (keycode == XK_Right)

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/29 13:42:39 by tchampio #+# #+# */
/* Updated: 2025/07/29 20:09:30 by tchampio ### ########.fr */
/* Updated: 2025/08/13 15:22:54 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,7 @@ typedef struct s_keypresses
bool is_d_pressed;
bool is_left_pressed;
bool is_right_pressed;
bool is_f_pressed;
} t_keypresses;
#endif // KEYPRESSES_H