diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_bad_boy_actions.c | 14 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 4 | ||||
-rw-r--r-- | src/ft_select_bad_boy_action.c | 82 | ||||
-rw-r--r-- | src/ft_time.c | 2 |
4 files changed, 85 insertions, 17 deletions
diff --git a/src/ft_bad_boy_actions.c b/src/ft_bad_boy_actions.c index 775e917..eada61a 100644 --- a/src/ft_bad_boy_actions.c +++ b/src/ft_bad_boy_actions.c @@ -43,16 +43,18 @@ void if (FT_OS == 2) { - r_x = (random() % 2 == 1) ? (1) : (-1); - r_y = (random() % 2 == 1) ? (1) : (-1); + r_x = random() % 3; + r_y = random() % 3; } else { - r_x = (rand() % 2 == 1) ? (1) : (-1); - r_y = (rand() % 2 == 1) ? (1) : (-1); + r_x = rand() % 3; + r_y = rand() % 3; } - sl->s_pos_x += (0.1 * r_x); - sl->s_pos_y += (0.1 * r_y); + r_x = (r_x == 2) ? (-1) : (r_x); + r_y = (r_y == 2) ? (-1) : (r_y); + sl->s_pos_x += (FT_MOVE_SPEED * 1.5 * r_x); + sl->s_pos_y += (FT_MOVE_SPEED * 1.5 * r_y); ft_bb_collision(old_y, old_x, sl, ml); ml->map[lround(old_y)][lround(old_x)] = '0'; ml->map[lround(sl->s_pos_y)][lround(sl->s_pos_x)] = 'e'; diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index e41484e..6df35a7 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -67,8 +67,8 @@ static void float dist; t_rgb rgb; - if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) - + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) + if ((dist = sqrt(pow(cl->plist.pos_x - sprite->s_pos_x, 2) + + pow(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) dist = 0.0001; rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * cl->tlist[sprite->current_sprite].img_w * sprite->tex_y + 2]; diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c index 34e0efe..5f4cc3a 100644 --- a/src/ft_select_bad_boy_action.c +++ b/src/ft_select_bad_boy_action.c @@ -13,6 +13,63 @@ #include <libft.h> #include <cub3d.h> #include <stdlib.h> +#include <math.h> + +/* +** bad_boy[].act[] - index summary +** ------------------------------- +** 0: wait +** 1: walk +** 2: fire +** +** rand() rules +** ------------ +** I. player is not in sight +** rand 0-3 | 0-2 wait | 3 walk +** II. player is in sight +** rand 0-7 | 0-1 wait | 2-5 walk | 6-7 +*/ + +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) +{ + int8_t r; + + if (FT_OS == 2) + r = random() % 4; + else + r = rand() % 4; + if (r == 3) + return (1); + else + return (0); + return (r); +} + +static int8_t + ft_set_r_ii(void) +{ + int8_t r; + + if (FT_OS == 2) + r = random() % 8; + else + r = rand() % 8; + if (r <= 1) + return (0); + else if (r >= 2 && r <= 5) + return (1); + else + return (2); + return (r); +} void ft_select_bad_boy_action(t_cub *cl) @@ -23,16 +80,25 @@ void i = 0; while (i < cl->mlist.sprite_nbr[13]) { - if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0) + 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][0], cl))) + { + r = ft_set_r_i(); + } + 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][0], cl))) { - if (FT_OS == 2) - r = random() % 2; - else - r = rand() % 2; - cl->bad_boy[i].act[r](&cl->bad_boy[i], - &cl->sprites[13][i], &cl->mlist); - cl->bad_boy[i].sleep = 1; + r = ft_set_r_ii(); } + else if (cl->bad_boy[i].life <= 0) + /* something */ + cl->bad_boy[i].act[r](&cl->bad_boy[i], + &cl->sprites[13][i], &cl->mlist); + cl->bad_boy[i].sleep = 1; i++; } } diff --git a/src/ft_time.c b/src/ft_time.c index 4d33dc8..0157fd8 100644 --- a/src/ft_time.c +++ b/src/ft_time.c @@ -45,7 +45,7 @@ void curr = clock(); dt[i] += curr - before; - if (cl->bad_boy[i].sleep == 1 && dt[i] > 0 && ft_clock_to_ms(dt[i]) > 700.0) + if (cl->bad_boy[i].sleep == 1 && dt[i] > 0 && ft_clock_to_ms(dt[i]) > 1500.0) { cl->bad_boy[i].sleep = 0; dt[i] = 0; |