fix: Added a currently aimed zombie pointer to the player struct and improved zombie checker function

This commit is contained in:
Theo Champion 2025-09-15 14:14:50 +02:00
parent 50164e94bb
commit 46b40540dc
4 changed files with 19 additions and 12 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/09/14 16:41:00 by tchampio ### ########.fr */
/* Updated: 2025/09/15 14:09:13 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -54,7 +54,9 @@ int game_loop(t_cub3d_data *data)
move_player(data);
handle_shooting(data);
move_sprites(data);
data->player.aimed_zombie = NULL;
raycaster(data, &ray);
ft_printf("Current aimed %p\n", data->player.aimed_zombie);
sprite_caster(data);
create_hud(data);
matrix_to_image(data);

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
/* Updated: 2025/09/10 15:51:55 by tchampio ### ########.fr */
/* Updated: 2025/09/15 13:18:49 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,7 @@
# include "../map/mapdata.h"
# include "../draw/img_data.h"
# include "../sprites/sprite.h"
typedef struct s_vec2
{
@ -55,6 +56,7 @@ typedef struct s_player
t_perks perk_order[3];
t_vec2 movement;
t_weapon weapon;
t_sprite *aimed_zombie;
} t_player;
#endif // PLAYER_H

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */
/* Updated: 2025/09/15 13:11:37 by tchampio ### ########.fr */
/* Updated: 2025/09/15 14:08:27 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,8 +19,8 @@
#include "../cub3d_data.h"
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include "../map/collision.h"
#include "../../libft/includes/libft.h"
void init_ray(t_ray *ray, int pos_x, t_player *player)
{

View file

@ -6,29 +6,32 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/15 13:08:48 by tchampio #+# #+# */
/* Updated: 2025/09/15 13:09:38 by tchampio ### ########.fr */
/* Updated: 2025/09/15 14:10:17 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "ray.h"
#include "../cub3d_data.h"
#include "../../libft/includes/libft.h"
#include <stdlib.h>
void check_for_zombies(t_ray *ray, t_cub3d_data *data)
{
int i;
int i;
i = 0;
while (i < data->sprite_counter)
{
if (data->sprite_list[i]->sprite_type == ZOMBIE
&& ray->map_x == (int)data->sprite_list[i]->x
if (ray->map_x == (int)data->sprite_list[i]->x
&& ray->map_y == (int)data->sprite_list[i]->y)
{
ft_printf("Zombie found %p\n", data->sprite_list[i]);
break ;
if (data->sprite_list[i]->sprite_type == ZOMBIE)
{
data->player.aimed_zombie = data->sprite_list[i];
break ;
}
else
data->player.aimed_zombie = NULL;
}
i++;
}
}