cub3d/src/player/player.c
Theo Champion faf5127829 feat(player): redid all the movement code more details in desc
- had to tamper at init with the map pointer to allow player to move
- tweaked movement speed
- allowed for multiple keys to be pressed at the same time
- added collisions
- had to modify minimap code because it segfaulted due to old code
2025-07-29 15:01:31 +02:00

68 lines
1.9 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* player.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/29 11:42:44 by tchampio #+# #+# */
/* Updated: 2025/07/29 14:44:44 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "player.h"
#include "../map/mapdata.h"
#include "../consts.h"
// east west
void init_lon(t_player *player, char dir)
{
if (dir == 'N')
{
player->dir_x = 0;
player->dir_y = -1;
player->plane_x = PLANE_VALUE;
player->plane_y = 0;
}
else
{
player->dir_x = 0;
player->dir_y = 1;
player->plane_x = -PLANE_VALUE;
player->plane_y = 0;
}
}
// north south
void init_lat(t_player *player, char dir)
{
if (dir == 'E')
{
player->dir_x = 1;
player->dir_y = 0;
player->plane_x = 0;
player->plane_y = PLANE_VALUE;
}
else
{
player->dir_x = -1;
player->dir_y = 0;
player->plane_x = 0;
player->plane_y = -PLANE_VALUE;
}
}
void init_player(t_player *player, t_mapdata *map)
{
char dir;
dir = map->map[map->starty][map->startx];
player->x = map->startx + 0.5;
player->y = map->starty + 0.5;
map->map[map->starty][map->startx] = '0';
player->health = 100;
player->points = 500;
if (dir == 'N' || dir == 'S')
init_lon(player, dir);
else
init_lat(player, dir);
}