diff options
author | Rudy Bousset <rbousset@z2r4p3.le-101.fr> | 2020-02-17 17:21:29 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r4p3.le-101.fr> | 2020-02-17 17:21:29 +0100 |
commit | fe33cb60b2355745237b49ecc969b86d2ea9101b (patch) | |
tree | daf91b320d82d420e78a9e6f6475a161df082ca6 /src/ft_key_events.c | |
parent | Norme (diff) | |
download | 42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.tar.gz 42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.tar.bz2 42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.tar.xz 42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.tar.zst 42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.zip |
Collision bav
Diffstat (limited to 'src/ft_key_events.c')
-rw-r--r-- | src/ft_key_events.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 395761e..ba7a537 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -37,12 +37,20 @@ static uint16_t } static void - ft_secure_player_pos(t_player *pl, t_map *ml) + ft_collision(float old_y, float old_x, t_player *pl, t_map *ml) { - (pl->pos_y < 1) ? (pl->pos_y = 1.1) : 0; - (pl->pos_x < 1) ? (pl->pos_x = 1.1) : 0; - (pl->pos_y > ml->map_h - 1.4) ? (pl->pos_y = ml->map_h - 1.4) : 0; - (pl->pos_x > ml->map_w - 1.4) ? (pl->pos_x = ml->map_w - 1.4) : 0; + const size_t x = pl->pos_x; + const size_t y = pl->pos_y; + + if (ml->map[y][x] == '1') + { + pl->pos_y = old_y; + pl->pos_x = old_x; + } + /* (pl->pos_y < 1) ? (pl->pos_y = 1.1) : 0; */ + /* (pl->pos_x < 1) ? (pl->pos_x = 1.1) : 0; */ + /* (pl->pos_y > ml->map_h - 1.4) ? (pl->pos_y = ml->map_h - 1.4) : 0; */ + /* (pl->pos_x > ml->map_w - 1.4) ? (pl->pos_x = ml->map_w - 1.4) : 0; */ } int @@ -50,6 +58,8 @@ int { int (*fun_ptr[6])(t_cub*); const uint16_t tmp_code = keycode; + const float old_y = clist->plist->pos_y; + const float old_x = clist->plist->pos_x; fun_ptr[0] = ft_w_key; fun_ptr[1] = ft_a_key; @@ -61,7 +71,7 @@ int if (keycode <= 5) { (*fun_ptr[keycode])(clist); - ft_secure_player_pos(clist->plist, clist->mlist); + ft_collision(old_y, old_x, clist->plist, clist->mlist); ft_draw_scene(clist); return (0); } |