change: moving with hitbox
This commit is contained in:
parent
d7903ec615
commit
20e92ef401
3 changed files with 57 additions and 14 deletions
3
algo.h
3
algo.h
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */
|
||||
/* Updated: 2024/10/15 16:57:48 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/10/17 14:19:12 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
|||
# define SCREEN_WIDTH 640 // px
|
||||
# define SCREEN_HEIGHT 480 // px
|
||||
# define FOV 0.66 // ? TODO unit
|
||||
# define HITBOX 0.25 // cases. should be more than MOVE_SPEED
|
||||
|
||||
extern void *g_mlx;
|
||||
extern void *g_win;
|
||||
|
|
53
move.c
53
move.c
|
@ -6,29 +6,56 @@
|
|||
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/10/17 12:29:23 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/10/17 14:20:10 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "algo.h"
|
||||
|
||||
static void push_from_wall(t_point_int c)
|
||||
{
|
||||
if (map_get_case(&g_map, c.x, c.y)->wall == EMPTY)
|
||||
return ;
|
||||
if (g_map.player.pos.x < c.x + 1 + HITBOX && g_map.player.pos.x > c.x + 1)
|
||||
g_map.player.pos.x = c.x + 1 + HITBOX;
|
||||
if (g_map.player.pos.x > c.x - HITBOX && g_map.player.pos.x < c.x)
|
||||
g_map.player.pos.x = c.x - HITBOX;
|
||||
if (g_map.player.pos.y < c.y + 1 + HITBOX && g_map.player.pos.y > c.y + 1)
|
||||
g_map.player.pos.y = c.y + 1 + HITBOX;
|
||||
if (g_map.player.pos.y > c.y - HITBOX && g_map.player.pos.y < c.y)
|
||||
g_map.player.pos.y = c.y - HITBOX;
|
||||
}
|
||||
|
||||
static void push_from_walls(void)
|
||||
{
|
||||
t_point_int c;
|
||||
t_point_int p;
|
||||
|
||||
p.x = g_map.player.pos.x;
|
||||
p.y = g_map.player.pos.y;
|
||||
c.x = p.x - 1;
|
||||
c.y = p.y;
|
||||
push_from_wall(c);
|
||||
c.x = p.x + 1;
|
||||
c.y = p.y;
|
||||
push_from_wall(c);
|
||||
c.x = p.x;
|
||||
c.y = p.y - 1;
|
||||
push_from_wall(c);
|
||||
c.x = p.x;
|
||||
c.y = p.y + 1;
|
||||
push_from_wall(c);
|
||||
}
|
||||
|
||||
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 * factor;
|
||||
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;
|
||||
g_map.player.pos.x += dir.x * MOVE_SPEED * factor;
|
||||
g_map.player.pos.y += dir.y * MOVE_SPEED * factor;
|
||||
push_from_walls();
|
||||
printf("%f %f\n", g_map.player.pos.x, g_map.player.pos.y);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
15
testmaps/good_big.cub
Normal file
15
testmaps/good_big.cub
Normal file
|
@ -0,0 +1,15 @@
|
|||
F 255,127,0
|
||||
EA eastimage
|
||||
NO theimageforthenorthwall
|
||||
C 0,2,67
|
||||
SO SOUTH!!!!!!1
|
||||
WE weeeee
|
||||
111111111
|
||||
100000001
|
||||
100000001
|
||||
100000001
|
||||
1000N0001
|
||||
100000001
|
||||
100000001
|
||||
100000001
|
||||
111111111
|
Loading…
Add table
Reference in a new issue