diff options
author | Rudy Bousset <rbousset@z2r4p1.le-101.fr> | 2020-02-14 21:00:02 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r4p1.le-101.fr> | 2020-02-14 21:00:02 +0100 |
commit | a95f7c219961b16be72febd645191e5a0d4aad4d (patch) | |
tree | a3a49e80b550742e4f9c5fe890bb6ef76ad2486e | |
parent | New define .h (diff) | |
download | 42-cub3d-a95f7c219961b16be72febd645191e5a0d4aad4d.tar.gz 42-cub3d-a95f7c219961b16be72febd645191e5a0d4aad4d.tar.bz2 42-cub3d-a95f7c219961b16be72febd645191e5a0d4aad4d.tar.xz 42-cub3d-a95f7c219961b16be72febd645191e5a0d4aad4d.tar.zst 42-cub3d-a95f7c219961b16be72febd645191e5a0d4aad4d.zip |
Good player spawn view for N and S, minimap bot left StarCraft style
-rw-r--r-- | inc/cub3d_defines.h | 19 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 1 | ||||
-rw-r--r-- | map/map_one.cub | 4 | ||||
-rw-r--r-- | src/ft_draw_map.c | 18 | ||||
-rw-r--r-- | src/ft_get_player_spawn.c | 60 | ||||
-rw-r--r-- | src/ft_init_lists.c | 1 | ||||
-rw-r--r-- | src/ft_key_events.c | 3 |
7 files changed, 78 insertions, 28 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index b129206..e6c98c5 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -6,28 +6,31 @@ */ # ifndef FT_W_KEY -# define FT_W_KEY 13 +# define FT_W_KEY 13 # endif # ifndef FT_A_KEY -# define FT_A_KEY 0 +# define FT_A_KEY 0 # endif # ifndef FT_S_KEY -# define FT_S_KEY 1 +# define FT_S_KEY 1 # endif # ifndef FT_D_KEY -# define FT_D_KEY 2 +# define FT_D_KEY 2 # endif # ifndef FT_L_ARR_KEY -# define FT_L_ARR_KEY 123 +# define FT_L_ARR_KEY 123 # endif # ifndef FT_R_ARR_KEY -# define FT_R_ARR_KEY 124 +# define FT_R_ARR_KEY 124 # endif # ifndef FT_ESC_KEY -# define FT_ESC_KEY 53 +# define FT_ESC_KEY 53 # endif # ifndef FT_F1_KEY -# define FT_F1_KEY 122 +# define FT_F1_KEY 122 +# endif +# ifndef FT_TAB_KEY +# define FT_TAB_KEY 48 # endif /* diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 9dae0be..eee6188 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -55,7 +55,6 @@ typedef struct s_player { float pos_x; float pos_y; - float view_side; float dir_x; float dir_y; float cam_x; diff --git a/map/map_one.cub b/map/map_one.cub index 1a82a84..902d106 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -6,8 +6,8 @@ EA ./path_to_the_east_texture WE ./path_to_the_west_texture S ./path_to_the_sprite_texture -F 200,225,145 -C 225,30,156 +F 150,150,145 +C 30,130,175 1 1 1 1 1 1 1 1 1 1 1 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 0 0 0 0 0 0 0 0 0 0 0 1 diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c index 202439b..2e17d69 100644 --- a/src/ft_draw_map.c +++ b/src/ft_draw_map.c @@ -13,6 +13,14 @@ #include <cub3d.h> #include <stdint.h> +static uint16_t + ft_y_offset(t_cub *clist) +{ + return (clist->wlist->y_size + - (clist->mlist->map_h * clist->mlist->scale) + + clist->mlist->scale - 1); +} + static void ft_draw_player(t_player *plist, t_cub *clist) { @@ -22,7 +30,7 @@ static void ft_draw_square( scale + (x * (scale)), - scale + (y * (scale)), + ft_y_offset(clist) + (y * (scale)), 0x009843fa, clist); } @@ -42,13 +50,13 @@ void { if (map[y][x] == '1') ft_draw_square(scale + (x * (scale)), - scale + (y * (scale)), 0x0000ffaa, clist); + ft_y_offset(clist) + (y * (scale)), 0x0000ffaa, clist); else if (map[y][x] == '2') ft_draw_square(scale + (x * (scale)), - scale + (y * (scale)), 0x0033ccff, clist); + ft_y_offset(clist) + (y * (scale)), 0x0033ccff, clist); else - ft_draw_square(scale + (x * (scale)), scale + (y * (scale)), - ft_rgb_to_hex(clist->f_rgb), clist); + ft_draw_square(scale + (x * (scale)), ft_y_offset(clist) + + (y * (scale)), ft_rgb_to_hex(clist->f_rgb), clist); x++; } x = 0; diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index 74e2231..c848872 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -12,20 +12,60 @@ #include <libft.h> #include <cub3d.h> +#include <math.h> #include <stdint.h> -static uint8_t - ft_get_view_side(char c) +static void + ft_get_e_dir(t_player *pl) { - if (c == 'N') - return (1); - else if (c == 'E') - return (2); + float sav_dir_x; + float sav_plane_x; + + sav_dir_x = pl->dir_x; + pl->dir_x = pl->dir_y; + pl->dir_y = sav_dir_x; + sav_plane_x = pl->plane_x; + pl->plane_x = pl->plane_y; + pl->plane_y = sav_plane_x; +} + +static void + ft_get_s_dir(t_player *pl) +{ + float sav_dir_x; + float sav_plane_x; + + sav_dir_x = pl->dir_x; + pl->dir_x = -pl->dir_x; + pl->dir_y = -pl->dir_y; + sav_plane_x = pl->plane_x; + pl->plane_x = -pl->plane_x; + pl->plane_y = -pl->plane_y; +} + +static void + ft_get_w_dir(t_player *pl) +{ + float sav_dir_x; + float sav_plane_x; + + sav_dir_x = pl->dir_x; + pl->dir_x = -pl->dir_y; + pl->dir_y = -sav_dir_x; + sav_plane_x = pl->plane_x; + pl->plane_x = -pl->plane_y; + pl->plane_y = -sav_plane_x; +} + +static void + ft_get_start_side(char c, t_player *pl) +{ + if (c == 'E') + ft_get_e_dir(pl); else if (c == 'S') - return (3); + ft_get_s_dir(pl); else if (c == 'W') - return (4); - return (1); + ft_get_w_dir(pl); } void @@ -44,7 +84,7 @@ void { plist->pos_x = x; plist->pos_y = y; - plist->view_side = ft_get_view_side(clist->mlist->map[y][x]); + ft_get_start_side(clist->mlist->map[y][x], clist->plist); return ; } x++; diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index a66634a..dc50231 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -37,7 +37,6 @@ static t_player return (NULL); plist->pos_x = 0; plist->pos_y = 0; - plist->view_side = 0; plist->cam_x = 0; plist->dir_x = -1; plist->dir_y = 0; diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 92928ea..395761e 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -32,6 +32,7 @@ static uint16_t (tmp_code == 5) ? (keycode = UINT16_MAX) : 0; (tmp_code == FT_ESC_KEY) ? (keycode = FT_ESC_KEY) : 0; (tmp_code == FT_F1_KEY) ? (keycode = FT_F1_KEY) : 0; + (tmp_code == FT_TAB_KEY) ? (keycode = FT_TAB_KEY) : 0; return (keycode); } @@ -66,7 +67,7 @@ int } else if (keycode == FT_ESC_KEY) return (ft_exit(0, (clist))); - else if (keycode == FT_F1_KEY) + else if (keycode == FT_F1_KEY || keycode == FT_TAB_KEY) return (ft_f1_key(clist)); return (0); } |