mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
dev: Added raycasting rule for zombies
This commit is contained in:
parent
d7781f44d2
commit
c7c71690e2
1 changed files with 18 additions and 4 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */
|
||||
/* Updated: 2025/09/09 14:07:24 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/09/14 17:40:53 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include "../map/collision.h"
|
||||
#include "../../libft/includes/libft.h"
|
||||
|
||||
void init_ray(t_ray *ray, int pos_x, t_player *player)
|
||||
{
|
||||
|
|
@ -55,10 +56,23 @@ void ray_calculate_step(t_ray *ray, t_player *player)
|
|||
}
|
||||
}
|
||||
|
||||
void calculate_wall_dist(t_ray *ray, t_mapdata *map)
|
||||
void calculate_wall_dist(t_ray *ray, int x, t_cub3d_data *data)
|
||||
{
|
||||
int i;
|
||||
while (true)
|
||||
{
|
||||
if (x == WIDTH / 2)
|
||||
{
|
||||
i = 0;
|
||||
while (i < data->sprite_counter)
|
||||
{
|
||||
if (data->sprite_list[i]->sprite_type == ZOMBIE && ray->map_x == (int)data->sprite_list[i]->x && ray->map_y == (int)data->sprite_list[i]->y)
|
||||
{
|
||||
ft_printf("Zombie found\n");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (ray->side_dist_x < ray->side_dist_y)
|
||||
{
|
||||
ray->side_dist_x += ray->delta_dist_x;
|
||||
|
|
@ -71,7 +85,7 @@ void calculate_wall_dist(t_ray *ray, t_mapdata *map)
|
|||
ray->map_y += ray->step_y;
|
||||
ray->side = SOUTH;
|
||||
}
|
||||
if (blocks_view(map, ray->map_x, ray->map_y))
|
||||
if (blocks_view(data->map, ray->map_x, ray->map_y))
|
||||
break ;
|
||||
}
|
||||
if (ray->side == NORTH)
|
||||
|
|
@ -107,7 +121,7 @@ void raycaster(t_cub3d_data *data, t_ray *ray)
|
|||
{
|
||||
init_ray(ray, x, &data->player);
|
||||
ray_calculate_step(ray, &data->player);
|
||||
calculate_wall_dist(ray, data->map);
|
||||
calculate_wall_dist(ray, x, data);
|
||||
calculate_wall_height(ray, &data->player);
|
||||
check_barricades(ray, data);
|
||||
render_walls(data, ray, x);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue