aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_collision.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-14 17:04:05 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-14 17:04:05 +0200
commit84ac504edbe27a56018b77fd93f289b90b1d8bdc (patch)
tree17e4484db8a227c17cd9fe469ae661714f3e36e7 /src/ft_collision.c
parentBad boys do not eat walls anymore (diff)
download42-cub3d-84ac504edbe27a56018b77fd93f289b90b1d8bdc.tar.gz
42-cub3d-84ac504edbe27a56018b77fd93f289b90b1d8bdc.tar.bz2
42-cub3d-84ac504edbe27a56018b77fd93f289b90b1d8bdc.tar.xz
42-cub3d-84ac504edbe27a56018b77fd93f289b90b1d8bdc.tar.zst
42-cub3d-84ac504edbe27a56018b77fd93f289b90b1d8bdc.zip
Fixed bad boys collision, reroll if hit a wall
Diffstat (limited to 'src/ft_collision.c')
-rw-r--r--src/ft_collision.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ft_collision.c b/src/ft_collision.c
index 385b2f7..6468433 100644
--- a/src/ft_collision.c
+++ b/src/ft_collision.c
@@ -95,3 +95,33 @@ int
}
return (0);
}
+
+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]))
+ {
+ 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]))
+ {
+ 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)]))
+ {
+ 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)]))
+ {
+ sl->s_pos_x = old_x;
+ return (1);
+ }
+ return (0);
+}