diff options
Diffstat (limited to 'src/ft_select_bad_boy_action.c')
-rw-r--r-- | src/ft_select_bad_boy_action.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c index 5f4cc3a..c716e33 100644 --- a/src/ft_select_bad_boy_action.c +++ b/src/ft_select_bad_boy_action.c @@ -25,9 +25,9 @@ ** rand() rules ** ------------ ** I. player is not in sight -** rand 0-3 | 0-2 wait | 3 walk +** rand(0-3) | [0-2] wait | [3] walk ** II. player is in sight -** rand 0-7 | 0-1 wait | 2-5 walk | 6-7 +** rand(0-7) | [0-1] wait | [2-3] walk | [4-7] fire */ static double @@ -50,7 +50,7 @@ static int8_t return (1); else return (0); - return (r); + return (0); } static int8_t @@ -64,11 +64,18 @@ static int8_t r = rand() % 8; if (r <= 1) return (0); - else if (r >= 2 && r <= 5) + else if (r >= 2 && r <= 3) return (1); else return (2); - return (r); + return (0); +} + +static void + ft_bb_act(int8_t r, int8_t i, t_cub *cl) +{ + cl->bad_boy[i].act[r](&cl->bad_boy[i], + &cl->sprites[13][i], &cl->mlist); } void @@ -77,28 +84,27 @@ void int8_t i; int8_t r; - i = 0; - while (i < cl->mlist.sprite_nbr[13]) + i = -1; + while (++i < cl->mlist.sprite_nbr[13]) { if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0 && (ft_get_dist(cl->sprites[13][i], cl) > FT_ENMY_SIGHT_RANGE - || cl->rlist.wall_dist_tab[cl->wlist.x_size / 2] > - ft_get_dist(cl->sprites[13][0], cl))) + || cl->rlist.wall_dist_tab[cl->wlist.x_size / 2] < + ft_get_dist(cl->sprites[13][i], cl))) { r = ft_set_r_i(); + ft_bb_act(r, i, cl); } else if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0 && (ft_get_dist(cl->sprites[13][i], cl) <= FT_ENMY_SIGHT_RANGE - || cl->rlist.wall_dist_tab[cl->wlist.x_size / 2] <= - ft_get_dist(cl->sprites[13][0], cl))) + && cl->rlist.wall_dist_tab[cl->wlist.x_size / 2] > + ft_get_dist(cl->sprites[13][i], cl))) { r = ft_set_r_ii(); + ft_bb_act(r, i, cl); } else if (cl->bad_boy[i].life <= 0) - /* something */ - cl->bad_boy[i].act[r](&cl->bad_boy[i], - &cl->sprites[13][i], &cl->mlist); + cl->bad_boy[i].does = 3; cl->bad_boy[i].sleep = 1; - i++; } } |