60 lines
1.9 KiB
C
60 lines
1.9 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* move.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */
|
|
/* Updated: 2024/10/15 18:22:58 by mcolonna ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "algo.h"
|
|
|
|
static int move(int factor)
|
|
{
|
|
t_point_double dir;
|
|
|
|
vector_from_rotation(&dir, g_map.player.rot, 1);
|
|
if (map_get_case(&g_map,
|
|
(int)(g_map.player.pos.x + dir.x * MOVE_SPEED * factor),
|
|
(int)(g_map.player.pos.y)
|
|
)->wall == EMPTY
|
|
)
|
|
g_map.player.pos.x += dir.x * MOVE_SPEED;
|
|
if (map_get_case(&g_map,
|
|
(int)(g_map.player.pos.x),
|
|
(int)(g_map.player.pos.y + dir.y * MOVE_SPEED * factor)
|
|
)->wall == EMPTY
|
|
)
|
|
g_map.player.pos.y += dir.y * MOVE_SPEED * factor;
|
|
return (0);
|
|
}
|
|
|
|
static int rotate(int factor)
|
|
{
|
|
g_map.player.rot += PI / ROT_SPEED_DIVIDE_PI * factor;
|
|
return (0);
|
|
}
|
|
|
|
// TODO leaks when quit?
|
|
|
|
int keypress(int keycode)
|
|
{
|
|
if (keycode == XK_Up || keycode == XK_z || keycode == XK_w)
|
|
move(+1);
|
|
if (keycode == XK_Down || keycode == XK_s)
|
|
move(-1);
|
|
if (keycode == XK_Right || keycode == XK_d)
|
|
rotate(+1);
|
|
if (keycode == XK_Left || keycode == XK_q || keycode == XK_a)
|
|
rotate(-1);
|
|
if (keycode == XK_Escape)
|
|
{
|
|
mlx_destroy_window(g_mlx, g_win);
|
|
exit(0);
|
|
}
|
|
draw_screen();
|
|
return (0);
|
|
}
|