diff options
author | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-29 19:56:03 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-29 19:56:03 +0100 |
commit | 7c4faa6a1a0c5c7f2b9545ab965c1002315bb491 (patch) | |
tree | 3f0947c76e50022ef5a89c434e77220461f2d024 | |
parent | commit (diff) | |
download | 42-cub3d-7c4faa6a1a0c5c7f2b9545ab965c1002315bb491.tar.gz 42-cub3d-7c4faa6a1a0c5c7f2b9545ab965c1002315bb491.tar.bz2 42-cub3d-7c4faa6a1a0c5c7f2b9545ab965c1002315bb491.tar.xz 42-cub3d-7c4faa6a1a0c5c7f2b9545ab965c1002315bb491.tar.zst 42-cub3d-7c4faa6a1a0c5c7f2b9545ab965c1002315bb491.zip |
Better collision merge
Diffstat (limited to '')
-rw-r--r-- | inc/cub3d_defines.h | 6 | ||||
-rw-r--r-- | map/map_one.cub | 2 | ||||
-rw-r--r-- | src/ft_key_loop.c | 62 |
3 files changed, 64 insertions, 6 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index f58c211..f5cfd8a 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -85,6 +85,12 @@ enum # define FT_ROT_SPEED 0.09 /* +** ====== MOVE SPEED ====== +*/ + +# define FT_COLL_MULT 0.225 + +/* ** ====== SCREEN ====== */ diff --git a/map/map_one.cub b/map/map_one.cub index 5a1fb78..bc926ee 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -12,7 +12,7 @@ F 50,190,124 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 0 2 0 0 0 0 0 0 0 0 0 0 0 1 -1 N 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 +1 W 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index 75aec65..429628e 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -15,13 +15,65 @@ #include <stdint.h> #include <stddef.h> +static uint64_t + ft_find_x(int32_t key, const t_player *pl) +{ + if (key == 0) + return (pl->pos_x + (pl->dir_y * FT_COLL_MULT)); + else if (key == 1) + return (pl->pos_x + (pl->dir_x * (FT_COLL_MULT / 2))); + else if (key == 2) + return (pl->pos_x - (pl->dir_y * FT_COLL_MULT)); + else if (key == 3) + return (pl->pos_x - (pl->dir_x * (FT_COLL_MULT / 2))); + return (1); +} + +static uint64_t + ft_find_y(int32_t key, const t_player *pl) +{ + if (key == 0) + return (pl->pos_y + (pl->dir_x * FT_COLL_MULT)); + else if (key == 1) + return (pl->pos_y - (pl->dir_y * (FT_COLL_MULT / 2))); + else if (key == 2) + return (pl->pos_y - (pl->dir_x * FT_COLL_MULT)); + else if (key == 3) + return (pl->pos_y + (pl->dir_y * (FT_COLL_MULT / 2))); + return (1); +} + static void - ft_collision(float old_y, float old_x, t_player *pl, t_map *ml) + ft_collision(float old_y, float old_x, int32_t key, t_cub *cl) { - const size_t x = pl->pos_x; - const size_t y = pl->pos_y; + uint64_t x; + uint64_t y; + t_player *pl; - if (ml->map[y][x] == '1') + pl = cl->plist; + x = pl->pos_x; + y = pl->pos_y; + if (key == 0) + { + x = ft_find_x(key, pl); + y = ft_find_y(key, pl); + } + else if (key == 1) + { + x = ft_find_x(key, pl); + y = ft_find_y(key, pl); + } + else if (key == 2) + { + x = ft_find_x(key, pl); + y = ft_find_y(key, pl); + } + else if (key == 3) + { + x = ft_find_x(key, pl); + y = ft_find_y(key, pl); + } + if (cl->mlist->map[y][x] == '1' || cl->mlist->map[y][x] == '2') { pl->pos_y = old_y; pl->pos_x = old_x; @@ -39,7 +91,7 @@ int while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5) { cl->key_ptr[cl->key_input[i]](cl); - ft_collision(old_y, old_x, cl->plist, cl->mlist); + ft_collision(old_y, old_x, cl->key_input[i], cl); if (cl->mlist->isnlvl) { if (ft_warp_level(cl) < 0) |