diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-03 16:54:34 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-03 16:54:34 +0200 |
commit | d3937497c05dedf94f533a73d6d310b26f84d527 (patch) | |
tree | ad475f1b0ba08a74941c4370bb6d4592a454fc1f | |
parent | Shooting fixed, now bad boys view (diff) | |
download | 42-cub3d-d3937497c05dedf94f533a73d6d310b26f84d527.tar.gz 42-cub3d-d3937497c05dedf94f533a73d6d310b26f84d527.tar.bz2 42-cub3d-d3937497c05dedf94f533a73d6d310b26f84d527.tar.xz 42-cub3d-d3937497c05dedf94f533a73d6d310b26f84d527.tar.zst 42-cub3d-d3937497c05dedf94f533a73d6d310b26f84d527.zip |
Optimization, still math missing
-rw-r--r-- | inc/cub3d_defines.h | 2 | ||||
-rw-r--r-- | map/map_seven.cub | 10 | ||||
-rw-r--r-- | src/ft_select_bad_boy_action.c | 65 |
3 files changed, 46 insertions, 31 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index 9b92d12..ad16b57 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 5.5 +# define FT_ENMY_SIGHT_RANGE 6.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 65dce79..b2917c9 100644 --- a/map/map_seven.cub +++ b/map/map_seven.cub @@ -15,14 +15,14 @@ C 150,150,150 1000000000000000001 1000000000000000001 100000000e000000001 -1000011111111100001 +1000000011100000001 1000000000000000001 1000000000000000001 1000000000000000001 1000000000000000001 -1000000000000000001 -1000000000000000001 -1000000!@#000000001 -1000000000000000001 +100000000000000000111111111111111111111111111111111111111111111111111111111111 +100000000000000000000000000000000000000000000000000000000000000000000000000001 +1000000!@#000000000000000000000000000000000000000000000000000000000e0000000001 +100000000000000000111111111111111111111111111111111111111111111111111111111111 10000000N0000000001 1111111111111111111 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++; } } |