cub3d/src/player.c
2025-05-15 13:20:17 +02:00

41 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* player.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */
/* Updated: 2025/05/15 13:15:36 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int player_create(t_game **game)
{
t_player *player;
player = malloc(sizeof(t_player));
if (!player)
return (FAILURE);
ft_memset(player, 0, sizeof(t_player));
player->pos.x = -1;
player->pos.y = -1;
player->speed = 3.f;
(*game)->player = player;
return (SUCCESS);
}
void player_render(t_screen *screen, t_player *player)
{
t_vec2 direction;
if (player->pos.x < 0 || player->pos.x >= screen->width
|| player->pos.y < 0 || player->pos.y >= screen->height)
return ;
render_circle(screen, mul(player->pos, TILE_SIZE), 4, 0x111111ff);
direction = add(mul(player->pos, TILE_SIZE), mul(player->dir, TILE_SIZE));
render_line(screen, mul(player->pos, TILE_SIZE), direction, 0xa83232ff);
}