aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_select_bad_boy_action.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-04 15:49:46 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-04 15:49:46 +0200
commit85a7a0916a15d0b43cf81a042e2684ec1a99fbc0 (patch)
tree2f1c86ee2f305c361eccadeb78693f75cd4105eb /src/ft_select_bad_boy_action.c
parentFixed skeuls shooting, now it's norme time (diff)
download42-cub3d-85a7a0916a15d0b43cf81a042e2684ec1a99fbc0.tar.gz
42-cub3d-85a7a0916a15d0b43cf81a042e2684ec1a99fbc0.tar.bz2
42-cub3d-85a7a0916a15d0b43cf81a042e2684ec1a99fbc0.tar.xz
42-cub3d-85a7a0916a15d0b43cf81a042e2684ec1a99fbc0.tar.zst
42-cub3d-85a7a0916a15d0b43cf81a042e2684ec1a99fbc0.zip
Normed
Diffstat (limited to 'src/ft_select_bad_boy_action.c')
-rw-r--r--src/ft_select_bad_boy_action.c91
1 files changed, 3 insertions, 88 deletions
diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c
index 7c845d5..2be17f3 100644
--- a/src/ft_select_bad_boy_action.c
+++ b/src/ft_select_bad_boy_action.c
@@ -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)
{
@@ -79,86 +72,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)
-{
- uint8_t hit;
- t_win *wl;
- t_player *pl;
- double teta;
- double a_big;
- double b_big;
- double sqx;
- double sqy;
-
- wl = &cl->wlist;
- pl = &cl->plist;
- a_big = 0;
- if (cl->sprites[13][id].s_pos_y > cl->plist.pos_y)
- {
- 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 (a_big < cl->plist.pos_y - cl->sprites[13][id].s_pos_y)
- a_big += 0.001;
- }
- else
- a_big = d;
- b_big = 0;
- if (cl->sprites[13][id].s_pos_x > cl->plist.pos_x)
- {
- while (b_big < cl->sprites[13][id].s_pos_x - cl->plist.pos_x)
- b_big += 0.0001;
- }
- else if (cl->sprites[13][id].s_pos_x < cl->plist.pos_x)
- {
- 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)
- 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;
- 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)
- {
- if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
- {
- cl->rlist.x_side_dist += cl->rlist.x_delta_dist;
- sqy += cl->mlist.x_step * 0.01;
- }
- else
- {
- cl->rlist.y_side_dist += cl->rlist.y_delta_dist;
- sqx += cl->mlist.y_step * 0.01;
- }
- 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));
-}
-
-void
+static void
ft_select_action(int8_t i, double d, t_cub *cl)
{
int8_t can_shoot;
@@ -191,7 +105,8 @@ void
i = 0;
while (i < cl->mlist.sprite_nbr[13])
{
- if ((d = 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)
{
ft_select_action(i, d, cl);