aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_draw_map.c18
-rw-r--r--src/ft_get_player_spawn.c60
-rw-r--r--src/ft_init_lists.c1
-rw-r--r--src/ft_key_events.c3
4 files changed, 65 insertions, 17 deletions
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);
}