51 lines
1.7 KiB
C
51 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* move.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */
|
|
/* Updated: 2024/11/13 21:42:40 by mcolonna ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "move.h"
|
|
#include "move_utils.h"
|
|
|
|
#include "utils.h"
|
|
#include "map.h"
|
|
#include "global.h"
|
|
#include "const.h"
|
|
#include "input.h"
|
|
|
|
static int move_forward(int factor)
|
|
{
|
|
t_point_double dir;
|
|
|
|
vector_from_rotation(&dir, g_map.player.rot, 1);
|
|
g_map.player.pos.x += dir.x * MOVE_SPEED * factor;
|
|
g_map.player.pos.y += dir.y * MOVE_SPEED * factor;
|
|
push_from_walls();
|
|
return (0);
|
|
}
|
|
|
|
static int rotate(int factor)
|
|
{
|
|
g_map.player.rot += PI / ROT_SPEED_DIVIDE_PI * factor;
|
|
return (0);
|
|
}
|
|
|
|
void move(void)
|
|
{
|
|
if (g_input_actions.up && !g_input_actions.down)
|
|
move_forward(+1);
|
|
if (g_input_actions.down && !g_input_actions.up)
|
|
move_forward(-1);
|
|
if (g_input_actions.right && !g_input_actions.left)
|
|
rotate(+1);
|
|
if (g_input_actions.left && !g_input_actions.right)
|
|
rotate(-1);
|
|
g_map.player.rot += (double)g_input_actions.rotate * MOUSE_ROTATION_SPEED;
|
|
g_input_actions.rotate = 0;
|
|
}
|