diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-19 18:46:10 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-19 18:46:10 +0200 |
commit | 5f6b5490f80be9e792ccaeb18548cca54a62826f (patch) | |
tree | 029898cbaa860a060cb01b8db62c5b4414af8812 /src | |
parent | Minilibx update (diff) | |
download | 42-cub3d-5f6b5490f80be9e792ccaeb18548cca54a62826f.tar.gz 42-cub3d-5f6b5490f80be9e792ccaeb18548cca54a62826f.tar.bz2 42-cub3d-5f6b5490f80be9e792ccaeb18548cca54a62826f.tar.xz 42-cub3d-5f6b5490f80be9e792ccaeb18548cca54a62826f.tar.zst 42-cub3d-5f6b5490f80be9e792ccaeb18548cca54a62826f.zip |
Fixed enemy hitbox
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_bad_boy_actions.c | 13 | ||||
-rw-r--r-- | src/ft_collision.c | 18 | ||||
-rw-r--r-- | src/ft_damage_bad_boy.c | 8 | ||||
-rw-r--r-- | src/ft_select_bad_boy_action.c | 1 | ||||
-rw-r--r-- | src/ft_time.c | 2 |
5 files changed, 27 insertions, 15 deletions
diff --git a/src/ft_bad_boy_actions.c b/src/ft_bad_boy_actions.c index fb2cdb7..4e332cc 100644 --- a/src/ft_bad_boy_actions.c +++ b/src/ft_bad_boy_actions.c @@ -14,6 +14,7 @@ #include <cub3d.h> #include <mlx.h> #include <stdlib.h> +#include <math.h> void ft_bb_wait(t_bad_boy *bl, t_sprite *sl, t_map *ml) @@ -46,16 +47,16 @@ void r = rand() % 4; sl->r = r; if (r == 0) - sl->s_pos_y += (FT_MOVE_SPEED * 1.5); + sl->s_pos_y += FT_ENMY_MOVE_SPEED; else if (r == 1) - sl->s_pos_y -= (FT_MOVE_SPEED * 1.5); + sl->s_pos_y -= FT_ENMY_MOVE_SPEED; else if (r == 2) - sl->s_pos_x -= (FT_MOVE_SPEED * 1.5); + sl->s_pos_x -= FT_ENMY_MOVE_SPEED; else if (r == 3) - sl->s_pos_x += (FT_MOVE_SPEED * 1.5); + sl->s_pos_x += FT_ENMY_MOVE_SPEED; ft_bb_collision(old_y, old_x, sl, ml); - ml->map[(uint64_t)old_y][(uint64_t)old_x] = '0'; - ml->map[(uint64_t)sl->s_pos_y][(uint64_t)sl->s_pos_x] = 'e'; + ml->map[llround(old_y)][llround(old_x)] = '0'; + ml->map[llround(sl->s_pos_y)][llround(sl->s_pos_x)] = 'e'; bl->does = 1; } diff --git a/src/ft_collision.c b/src/ft_collision.c index 6468433..ba44d49 100644 --- a/src/ft_collision.c +++ b/src/ft_collision.c @@ -15,6 +15,7 @@ #include <mlx.h> #include <stddef.h> #include <stdint.h> +#include <math.h> #include <time.h> static uint64_t @@ -96,29 +97,38 @@ int return (0); } +/* +** sl->r index list +** ------------------ +** 0: goes south +** 1: goes north +** 2: goes west +** 3: goes east +*/ + int8_t ft_bb_collision(double old_y, double old_x, t_sprite *sl, t_map *ml) { if (sl->r == 0 && !ft_ischarset("0e", - ml->map[(uint64_t)(sl->s_pos_y + 1.5)][(uint64_t)old_x])) + ml->map[llround(sl->s_pos_y + 0.4)][llround(old_x)])) { sl->s_pos_y = old_y; return (1); } else if (sl->r == 1 && !ft_ischarset("0e", - ml->map[(uint64_t)(sl->s_pos_y - 0.5)][(uint64_t)old_x])) + ml->map[llround(sl->s_pos_y - 0.4)][llround(old_x)])) { sl->s_pos_y = old_y; return (1); } else if (sl->r == 2 && !ft_ischarset("0e", - ml->map[(uint64_t)old_y][(uint64_t)(sl->s_pos_x - 0.5)])) + ml->map[llround(old_y)][llround(sl->s_pos_x - 0.4)])) { sl->s_pos_x = old_x; return (1); } else if (sl->r == 3 && !ft_ischarset("0e", - ml->map[(uint64_t)old_y][(uint64_t)(sl->s_pos_x + 1.5)])) + ml->map[llround(old_y)][llround(sl->s_pos_x + 0.4)])) { sl->s_pos_x = old_x; return (1); diff --git a/src/ft_damage_bad_boy.c b/src/ft_damage_bad_boy.c index ffbd2fe..36c082f 100644 --- a/src/ft_damage_bad_boy.c +++ b/src/ft_damage_bad_boy.c @@ -22,8 +22,8 @@ static uint8_t i = 0; while (i < cl->mlist.sprite_nbr[13]) { - if ((uint64_t)cl->sprites[13][i].s_pos_x == cl->rlist.sqx && - (uint64_t)cl->sprites[13][i].s_pos_y == cl->rlist.sqy) + if (llround(cl->sprites[13][i].s_pos_x) == (int64_t)cl->rlist.sqx && + llround(cl->sprites[13][i].s_pos_y) == (int64_t)cl->rlist.sqy) break ; i++; } @@ -47,8 +47,8 @@ void { cl->sfx[13].sfx_play(cl->sfx); cl->bad_boy[id].isdead = 1; - cl->mlist.map[(uint64_t)cl->sprites[13][id].s_pos_y] - [(uint64_t)cl->sprites[13][id].s_pos_x] = 'x'; + cl->mlist.map[llround(cl->sprites[13][id].s_pos_y)] + [llround(cl->sprites[13][id].s_pos_x)] = 'x'; } else if (cl->bad_boy[id].does != 3) cl->sfx[14].sfx_play(cl->sfx); diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c index 2be17f3..b824306 100644 --- a/src/ft_select_bad_boy_action.c +++ b/src/ft_select_bad_boy_action.c @@ -87,6 +87,7 @@ static void can_shoot == 1)) { r = ft_set_r_ii(); + r = ((r == 1) && (d < 2.0)) ? (2) : (r); ft_bb_act(r, i, cl); } else if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0) diff --git a/src/ft_time.c b/src/ft_time.c index 128d890..73d2379 100644 --- a/src/ft_time.c +++ b/src/ft_time.c @@ -49,7 +49,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]) > 500.0) { cl->bad_boy[i].sleep = 0; dt[i] = 0; |