aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-04 15:12:24 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-04 15:12:24 +0200
commit15107edc81dd51feea112f08e05dd6f3a55024cb (patch)
tree9cf5d639f0588610ef26e879c5031dbd074b2d7c
parentNot quite done (diff)
download42-cub3d-15107edc81dd51feea112f08e05dd6f3a55024cb.tar.gz
42-cub3d-15107edc81dd51feea112f08e05dd6f3a55024cb.tar.bz2
42-cub3d-15107edc81dd51feea112f08e05dd6f3a55024cb.tar.xz
42-cub3d-15107edc81dd51feea112f08e05dd6f3a55024cb.tar.zst
42-cub3d-15107edc81dd51feea112f08e05dd6f3a55024cb.zip
Fixed skeuls shooting, now it's norme time
-rw-r--r--inc/cub3d_defines.h2
-rw-r--r--map/map_seven.cub8
-rw-r--r--src/ft_select_bad_boy_action.c72
3 files changed, 46 insertions, 36 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index 74a228d..2c66bfe 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -309,7 +309,7 @@ enum
# define FT_WEAP_THREE_STRT_AMMO 10
# define FT_WEAP_MAX_AMMO 1000
# define FT_ENMY_STRT_LIFE 10
-# define FT_ENMY_SIGHT_RANGE 6.5
+# define FT_ENMY_SIGHT_RANGE 8.5
# define FT_ENMY_DAMAGE_AMOUNT 14
# define FT_W_ONE_DANAGE_AMOUNT 5
# define FT_W_TWO_DANAGE_AMOUNT 3
diff --git a/map/map_seven.cub b/map/map_seven.cub
index ec7689e..4c5fad3 100644
--- a/map/map_seven.cub
+++ b/map/map_seven.cub
@@ -13,16 +13,16 @@ C 150,150,150
1111111111111111111
1000000000000000001
-1000000000000000001
-100000000e000000001
-1000000011100000001
+1000000000000000011
1000000000000000001
1000000000000000001
1000000000000000001
1000000000000000001
+100000000e000000001
1000000000000000001
+1000000001000000001
1000000000000000001
1000000!@#000000001
1000000000000000001
-10000000N0000000001
+100000000N000000001
1111111111111111111
diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c
index 3f3ca6f..7c845d5 100644
--- a/src/ft_select_bad_boy_action.c
+++ b/src/ft_select_bad_boy_action.c
@@ -79,6 +79,7 @@ static void
&cl->sprites[13][i], &cl->mlist);
}
+#include <stdio.h>
int8_t
ft_can_it_shoot(int8_t id, double d, t_cub *cl)
{
@@ -86,35 +87,43 @@ int8_t
t_win *wl;
t_player *pl;
double teta;
- double a2;
+ double a_big;
+ double b_big;
+ double sqx;
+ double sqy;
wl = &cl->wlist;
pl = &cl->plist;
- a2 = 0;
+ a_big = 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.0005;
+ while (a_big < cl->sprites[13][id].s_pos_y - cl->plist.pos_y)
+ a_big += 0.001;
}
else if (cl->sprites[13][id].s_pos_y < cl->plist.pos_y)
{
- while (a2 < cl->plist.pos_y - cl->sprites[13][id].s_pos_y)
- a2 += 0.0005;
+ while (a_big < cl->plist.pos_y - cl->sprites[13][id].s_pos_y)
+ a_big += 0.001;
}
else
- a2 = d;
- if (a2 != d)
+ a_big = d;
+ b_big = 0;
+ if (cl->sprites[13][id].s_pos_x > cl->plist.pos_x)
{
- teta = acos(a2 / d);
- cl->rlist.y_ray_dir = 1 * cos(teta);
- cl->rlist.x_ray_dir = 1 * sin(teta);
+ while (b_big < cl->sprites[13][id].s_pos_x - cl->plist.pos_x)
+ b_big += 0.0001;
}
- else
+ else if (cl->sprites[13][id].s_pos_x < cl->plist.pos_x)
{
- teta = 0.0;
- cl->rlist.y_ray_dir = 1;
- cl->rlist.x_ray_dir = 1 * sin(teta);
+ while (b_big < cl->plist.pos_x - cl->sprites[13][id].s_pos_x)
+ b_big += 0.0001;
}
+ if (a_big > b_big)
+ teta = acos(a_big / d);
+ else
+ teta = asin(b_big / d);
+ cl->rlist.y_ray_dir = 1 * cos(teta);
+ cl->rlist.x_ray_dir = 1 * sin(teta);
if (cl->plist.pos_y > cl->sprites[13][id].s_pos_y)
cl->rlist.y_ray_dir = -cl->rlist.y_ray_dir;
if (cl->plist.pos_x > cl->sprites[13][id].s_pos_x)
@@ -122,27 +131,28 @@ int8_t
hit = 0;
cl->rlist.y_ray_pos = cl->plist.pos_y;
cl->rlist.x_ray_pos = cl->plist.pos_x;
- cl->rlist.sqy = lround(cl->rlist.y_ray_pos);
- cl->rlist.sqx = lround(cl->rlist.x_ray_pos);
+ sqy = cl->rlist.y_ray_pos;
+ sqx = cl->rlist.x_ray_pos;
ft_detection_init_x(cl);
ft_detection_init_y(cl);
- while (hit == 0 &&
- (cl->rlist.sqy != (unsigned)lround(cl->sprites[13][id].s_pos_y) ||
- cl->rlist.sqx != (unsigned)lround(cl->sprites[13][id].s_pos_x)))
+ while (hit == 0)
{
if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
{
cl->rlist.x_side_dist += cl->rlist.x_delta_dist;
- cl->rlist.sqy += cl->mlist.x_step;
- cl->rlist.side = 0;
+ sqy += cl->mlist.x_step * 0.01;
}
else
{
cl->rlist.y_side_dist += cl->rlist.y_delta_dist;
- cl->rlist.sqx += cl->mlist.y_step;
- cl->rlist.side = 1;
+ sqx += cl->mlist.y_step * 0.01;
}
- if (cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx] == '1')
+ if ((sqy >= cl->sprites[13][id].s_pos_y - 0.15 &&
+ sqy <= cl->sprites[13][id].s_pos_y + 0.15) &&
+ (sqx >= cl->sprites[13][id].s_pos_x - 0.15 &&
+ sqx <= cl->sprites[13][id].s_pos_x + 0.15))
+ break ;
+ if (cl->mlist.map[(uint64_t)(sqy + 0.5)][(uint64_t)(sqx + 0.5)] == '1')
hit = 1;
}
return ((hit == 1) ? (0) : (1));
@@ -176,16 +186,16 @@ void
ft_select_bad_boy_action(t_cub *cl)
{
int8_t i;
- /* double d; */
+ double d;
i = 0;
while (i < cl->mlist.sprite_nbr[13])
{
- /* if ((d = ft_get_dist(cl->sprites[13][i], cl)) */
- /* <= 4 * FT_ENMY_SIGHT_RANGE && cl->bad_boy[i].sleep == 0) */
- /* { */
- ft_select_action(i, ft_get_dist(cl->sprites[13][i], cl), cl);
- /* } */
+ if ((d = ft_get_dist(cl->sprites[13][i], cl))
+ <= 3 * FT_ENMY_SIGHT_RANGE && cl->bad_boy[i].sleep == 0)
+ {
+ ft_select_action(i, d, cl);
+ }
i++;
}
}