cub3d/src/collision.c
2025-05-28 17:15:22 +02:00

62 lines
1.9 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* collision.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
/* Updated: 2025/05/28 17:13:24 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "collision.h"
void collect(t_player *player)
{
player->battery += 0.5f;
if (player->battery > 1.f)
player->battery = 1.f;
}
int collision_sprite(t_map *map, t_player *player, double xa, double ya)
{
t_sprite *sprites;
int i;
sprites = map->sprites;
i = 0;
while (i < map->n_sprites)
{
if (sprites[i].type == SPRITE_TYPE_COLLECTIBLE)
{
if (fabs(player->pos.x + xa - sprites[i].pos.x) < 0.5
&& fabs(player->pos.y + ya - sprites[i].pos.y) < 0.5)
{
sprites[i].type = SPRITE_TYPE_COLLECTED;
collect(player);
return (1);
}
}
i++;
}
return (0);
}
int collision_horizontal(t_map *map, t_player *player, double xa)
{
t_tile tile;
tile = get_tile(map, (int)((player->pos.x + xa)), (int)((player->pos.y)));
return (tile != TILE_WALL && tile != TILE_VOID);
}
int collision_vertical(t_map *map, t_player *player, double ya)
{
t_tile tile;
tile = get_tile(map, (int)((player->pos.x)), (int)((player->pos.y + ya)));
return (tile != TILE_WALL && tile != TILE_VOID);
}