diff options
Diffstat (limited to 'src/ft_select_bad_boy_action.c')
-rw-r--r-- | src/ft_select_bad_boy_action.c | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c index 73b3f9a..2be17f3 100644 --- a/src/ft_select_bad_boy_action.c +++ b/src/ft_select_bad_boy_action.c @@ -16,8 +16,8 @@ #include <math.h> /* -** bad_boy[].act[] - index summary -** ------------------------------- +** bad_boy.act[] - index summary +** ----------------------------- ** 0: wait ** 1: walk ** 2: fire @@ -30,13 +30,6 @@ ** rand(0-7) | [0-1] wait | [2] walk | [3-7] fire */ -static double - ft_get_dist(t_sprite sprite, t_cub *cl) -{ - return (sqrt(pow(cl->plist.pos_x - sprite.s_pos_x, 2) + - pow(cl->plist.pos_y - sprite.s_pos_y, 2))); -} - static int8_t ft_set_r_i(void) { @@ -74,37 +67,50 @@ static int8_t static void ft_bb_act(int8_t r, int8_t i, t_cub *cl) { + cl->bad_boy[i].sleep = 1; cl->bad_boy[i].act[r](&cl->bad_boy[i], &cl->sprites[13][i], &cl->mlist); - cl->bad_boy[i].sleep = 1; +} + +static void + ft_select_action(int8_t i, double d, t_cub *cl) +{ + int8_t can_shoot; + int8_t r; + + if (cl->bad_boy[i].life <= 0) + cl->bad_boy[i].does = 3; + else + can_shoot = ft_can_it_shoot(i, d, cl); + if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0 && + (d <= FT_ENMY_SIGHT_RANGE && + can_shoot == 1)) + { + r = ft_set_r_ii(); + ft_bb_act(r, i, cl); + } + else if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0) + { + r = ft_set_r_i(); + ft_bb_act(r, i, cl); + } } void ft_select_bad_boy_action(t_cub *cl) { int8_t i; - int8_t r; + double d; - i = -1; - while (++i < cl->mlist.sprite_nbr[13]) + i = 0; + 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][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][i], cl))) + if ((d = sqrt(pow(cl->plist.pos_x - cl->sprites[13][i].s_pos_x, 2) + + pow(cl->plist.pos_y - cl->sprites[13][i].s_pos_y, 2))) + <= 3 * FT_ENMY_SIGHT_RANGE && cl->bad_boy[i].sleep == 0) { - r = ft_set_r_ii(); - ft_bb_act(r, i, cl); + ft_select_action(i, d, cl); } - else if (cl->bad_boy[i].life <= 0) - cl->bad_boy[i].does = 3; + i++; } } |