diff options
Diffstat (limited to '')
-rw-r--r-- | src/ft_bad_boy_actions.c | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/src/ft_bad_boy_actions.c b/src/ft_bad_boy_actions.c index 269ba0d..220e5ee 100644 --- a/src/ft_bad_boy_actions.c +++ b/src/ft_bad_boy_actions.c @@ -24,41 +24,48 @@ void bl->does = 0; } -static void - ft_bb_collision(double old_y, double old_x, t_sprite *sl, t_map *ml) -{ - if (!ft_ischarset("0e", ml->map[(uint64_t)old_y][(uint64_t)sl->s_pos_x])) - sl->s_pos_x = old_x; - if (!ft_ischarset("0e", ml->map[(uint64_t)sl->s_pos_y][(uint64_t)old_x])) - sl->s_pos_y = old_y; -} +/* +** rand(3) index list +** ------------------ +** rand() 0 - 3 +** 0: goes south +** 1: goes north +** 2: goes west +** 3: goes east +*/ -void - ft_bb_walk(t_bad_boy *bl, t_sprite *sl, t_map *ml) +static int8_t + ft_bb_actual_walk(t_bad_boy *bl, t_sprite *sl, t_map *ml) { - int8_t r_x; - int8_t r_y; + int8_t r; const double old_x = sl->s_pos_x; const double old_y = sl->s_pos_y; if (FT_OS == 2) - { - r_x = random() % 3; - r_y = random() % 3; - } + r = random() % 4; else - { - r_x = rand() % 3; - r_y = rand() % 3; - } - r_x = (r_x == 2) ? (-1) : (r_x); - r_y = (r_y == 2) ? (-1) : (r_y); - sl->s_pos_x += (FT_MOVE_SPEED * 1.5 * r_x); - sl->s_pos_y += (FT_MOVE_SPEED * 1.5 * r_y); - ft_bb_collision(old_y, old_x, sl, ml); + r = rand() % 4; + sl->r = r; + if (r == 0) + sl->s_pos_y += (FT_MOVE_SPEED * 1.5); + else if (r == 1) + sl->s_pos_y -= (FT_MOVE_SPEED * 1.5); + else if (r == 2) + sl->s_pos_x -= (FT_MOVE_SPEED * 1.5); + else if (r == 3) + sl->s_pos_x += (FT_MOVE_SPEED * 1.5); + if (ft_bb_collision(old_y, old_x, sl, ml)) + return (ft_bb_actual_walk(bl, sl, ml)); ml->map[(uint64_t)old_y][(uint64_t)old_x] = '0'; ml->map[(uint64_t)sl->s_pos_y][(uint64_t)sl->s_pos_x] = 'e'; bl->does = 1; + return (0); +} + +void + ft_bb_walk(t_bad_boy *bl, t_sprite *sl, t_map *ml) +{ + ft_bb_actual_walk(bl, sl, ml); } /* |