aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_select_bad_boy_action.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_select_bad_boy_action.c')
-rw-r--r--src/ft_select_bad_boy_action.c65
1 files changed, 40 insertions, 25 deletions
diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c
index 08d7489..a151432 100644
--- a/src/ft_select_bad_boy_action.c
+++ b/src/ft_select_bad_boy_action.c
@@ -74,9 +74,9 @@ 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;
}
int8_t
@@ -93,14 +93,15 @@ int8_t
hit = 0;
cl->rlist.y_ray_pos = cl->plist.pos_y;
cl->rlist.x_ray_pos = cl->plist.pos_x;
- cl->rlist.y_ray_dir = pl->dir_y;
+ cl->rlist.y_ray_dir = -pl->dir_y;
cl->rlist.x_ray_dir = pl->dir_x;
cl->rlist.sqy = (uint64_t)cl->rlist.y_ray_pos;
cl->rlist.sqx = (uint64_t)cl->rlist.x_ray_pos;
ft_detection_init_x(cl);
ft_detection_init_y(cl);
- while (hit == 0 && (cl->rlist.sqy != (uint64_t)cl->sprites[13][id].s_pos_y &&
- cl->rlist.sqx != (uint64_t)cl->sprites[13][id].s_pos_x))
+ while (hit == 0 &&
+ (cl->rlist.sqy != (uint64_t)cl->sprites[13][id].s_pos_y ||
+ cl->rlist.sqx != (uint64_t)cl->sprites[13][id].s_pos_x))
{
if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
{
@@ -115,38 +116,52 @@ int8_t
cl->rlist.side = 1;
}
if (cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx] == '1')
- hit = 1;
+ hit = 1;
}
return ((hit == 1) ? (0) : (1));
}
+static void
+ ft_select_action(int8_t i, t_cub *cl)
+{
+ int8_t can_shoot;
+ int8_t r;
+
+ can_shoot = ft_can_it_shoot(i, cl);
+ if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0 &&
+ (ft_get_dist(cl->sprites[13][i], cl) <= 1 || 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 &&
+ (ft_get_dist(cl->sprites[13][i], cl) <= 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 &&
+ ft_get_dist(cl->sprites[13][i], cl) > FT_ENMY_SIGHT_RANGE)
+ {
+ r = ft_set_r_i();
+ ft_bb_act(r, i, cl);
+ }
+ else if (cl->bad_boy[i].life <= 0)
+ cl->bad_boy[i].does = 3;
+}
void
ft_select_bad_boy_action(t_cub *cl)
{
int8_t i;
- int8_t r;
- int8_t can_shoot;
- i = -1;
- can_shoot = 0;
- while (++i < cl->mlist.sprite_nbr[13])
+ i = 0;
+ while (i < cl->mlist.sprite_nbr[13])
{
- can_shoot = ft_can_it_shoot(i, cl);
- 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 ||
- can_shoot == 0))
- {
- 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 &&
- can_shoot == 1))
+ if (ft_get_dist(cl->sprites[13][i], cl) < 4 * FT_ENMY_SIGHT_RANGE)
{
- r = ft_set_r_ii();
- ft_bb_act(r, i, cl);
+ ft_select_action(i, cl);
}
- else if (cl->bad_boy[i].life <= 0)
- cl->bad_boy[i].does = 3;
+ i++;
}
}