From 5f6b5490f80be9e792ccaeb18548cca54a62826f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 19 Apr 2020 18:46:10 +0200 Subject: Fixed enemy hitbox --- src/ft_collision.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/ft_collision.c') diff --git a/src/ft_collision.c b/src/ft_collision.c index 6468433..ba44d49 100644 --- a/src/ft_collision.c +++ b/src/ft_collision.c @@ -15,6 +15,7 @@ #include #include #include +#include #include static uint64_t @@ -96,29 +97,38 @@ int return (0); } +/* +** sl->r index list +** ------------------ +** 0: goes south +** 1: goes north +** 2: goes west +** 3: goes east +*/ + int8_t ft_bb_collision(double old_y, double old_x, t_sprite *sl, t_map *ml) { if (sl->r == 0 && !ft_ischarset("0e", - ml->map[(uint64_t)(sl->s_pos_y + 1.5)][(uint64_t)old_x])) + ml->map[llround(sl->s_pos_y + 0.4)][llround(old_x)])) { sl->s_pos_y = old_y; return (1); } else if (sl->r == 1 && !ft_ischarset("0e", - ml->map[(uint64_t)(sl->s_pos_y - 0.5)][(uint64_t)old_x])) + ml->map[llround(sl->s_pos_y - 0.4)][llround(old_x)])) { sl->s_pos_y = old_y; return (1); } else if (sl->r == 2 && !ft_ischarset("0e", - ml->map[(uint64_t)old_y][(uint64_t)(sl->s_pos_x - 0.5)])) + ml->map[llround(old_y)][llround(sl->s_pos_x - 0.4)])) { sl->s_pos_x = old_x; return (1); } else if (sl->r == 3 && !ft_ischarset("0e", - ml->map[(uint64_t)old_y][(uint64_t)(sl->s_pos_x + 1.5)])) + ml->map[llround(old_y)][llround(sl->s_pos_x + 0.4)])) { sl->s_pos_x = old_x; return (1); -- cgit v1.2.3