diff options
Diffstat (limited to 'src/ft_collision.c')
-rw-r--r-- | src/ft_collision.c | 18 |
1 files changed, 14 insertions, 4 deletions
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 <mlx.h> #include <stddef.h> #include <stdint.h> +#include <math.h> #include <time.h> 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); |