aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-03 22:20:03 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-03 22:20:03 +0200
commit46e5cbabdf6c9791a050953967edf24b2c41141a (patch)
tree6fb500115e74811f616fc79bf1fbcde0083d224f /src
parentGet the teta (diff)
download42-cub3d-46e5cbabdf6c9791a050953967edf24b2c41141a.tar.gz
42-cub3d-46e5cbabdf6c9791a050953967edf24b2c41141a.tar.bz2
42-cub3d-46e5cbabdf6c9791a050953967edf24b2c41141a.tar.xz
42-cub3d-46e5cbabdf6c9791a050953967edf24b2c41141a.tar.zst
42-cub3d-46e5cbabdf6c9791a050953967edf24b2c41141a.zip
YES
Diffstat (limited to 'src')
-rw-r--r--src/ft_key_loop.c1
-rw-r--r--src/ft_select_bad_boy_action.c55
2 files changed, 37 insertions, 19 deletions
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index 281c81e..a59a80c 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -32,6 +32,7 @@ int
ft_handle_keys(i, old_y, old_x, cl);
i++;
}
+ /* TODO: Don't kill me so fast */
ft_check_bad_boy_shoot(cl);
cl->moves = (cl->key_input[0] == -1) ? (0) : (cl->moves);
begin_frame = clock();
diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c
index 9eaaa90..5a4f5be 100644
--- a/src/ft_select_bad_boy_action.c
+++ b/src/ft_select_bad_boy_action.c
@@ -80,29 +80,51 @@ static void
}
int8_t
- ft_can_it_shoot(int8_t id, t_cub *cl)
+ ft_can_it_shoot(int8_t id, double d, t_cub *cl)
{
uint8_t hit;
t_win *wl;
t_player *pl;
- int16_t teta;
+ double teta;
+ double a2;
- (void)id;
- (void)cl;
wl = &cl->wlist;
pl = &cl->plist;
+ a2 = 0;
+ if (cl->sprites[13][id].s_pos_y > cl->plist.pos_y)
+ {
+ while (a2 < cl->sprites[13][id].s_pos_y - cl->plist.pos_y)
+ a2 += 0.005;
+ }
+ else
+ {
+ while (a2 < cl->plist.pos_y - cl->sprites[13][id].s_pos_y)
+ a2 += 0.005;
+ }
+ if (a2 != d)
+ {
+ teta = acos(a2 / d);
+ cl->rlist.y_ray_dir = 1 * cos(teta);
+ cl->rlist.x_ray_dir = 1 * sin(teta);
+ }
+ else
+ {
+ teta = 0.0;
+ cl->rlist.y_ray_dir = 1;
+ cl->rlist.x_ray_dir = 1 * sin(teta);
+ }
+ if (cl->plist.pos_x > cl->sprites[13][id].s_pos_x)
+ cl->rlist.x_ray_dir = -cl->rlist.x_ray_dir;
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.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))
+ (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)
{
@@ -122,20 +144,17 @@ int8_t
return ((hit == 1) ? (0) : (1));
}
-static void
+void
ft_select_action(int8_t i, double d, t_cub *cl)
{
int8_t can_shoot;
int8_t r;
- can_shoot = ft_can_it_shoot(i, cl);
+ 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 <= 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 &&
(d <= FT_ENMY_SIGHT_RANGE &&
can_shoot == 1))
{
@@ -148,8 +167,6 @@ static void
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
@@ -162,7 +179,7 @@ void
while (i < cl->mlist.sprite_nbr[13])
{
if ((d = ft_get_dist(cl->sprites[13][i], cl))
- <= 4 * FT_ENMY_SIGHT_RANGE)
+ <= 4 * FT_ENMY_SIGHT_RANGE && cl->bad_boy[i].sleep == 0)
{
ft_select_action(i, d, cl);
}