diff options
-rw-r--r-- | src/ft_basic_keys.c | 17 | ||||
-rw-r--r-- | src/ft_detect.c | 2 | ||||
-rw-r--r-- | src/ft_extra_keys.c | 5 | ||||
-rw-r--r-- | src/ft_raycasting.c | 2 |
4 files changed, 19 insertions, 7 deletions
diff --git a/src/ft_basic_keys.c b/src/ft_basic_keys.c index 48fc009..d147486 100644 --- a/src/ft_basic_keys.c +++ b/src/ft_basic_keys.c @@ -17,10 +17,11 @@ int ft_w_key(t_cub *clist) { t_player *pl; + const float move_speed = 0.2; pl = clist->plist; - pl->pos_y += 0.2 * (-1); - pl->pos_x += 0; + pl->pos_y += move_speed * pl->dir_x; + pl->pos_x += move_speed * pl->dir_y; return (0); } @@ -28,9 +29,11 @@ int ft_a_key(t_cub *clist) { t_player *pl; + const float move_speed = 0.1; pl = clist->plist; - pl->pos_x -= 0.2; + pl->pos_y += move_speed * -pl->dir_y; + pl->pos_x += move_speed * pl->dir_x; return (0); } @@ -38,9 +41,11 @@ int ft_s_key(t_cub *clist) { t_player *pl; + const float move_speed = 0.2; pl = clist->plist; - pl->pos_y += 0.2; + pl->pos_y += move_speed * -pl->dir_x; + pl->pos_x += move_speed * -pl->dir_y; return (0); } @@ -48,8 +53,10 @@ int ft_d_key(t_cub *clist) { t_player *pl; + const float move_speed = 0.1; pl = clist->plist; - pl->pos_x += 0.2; + pl->pos_y += move_speed * pl->dir_y; + pl->pos_x += move_speed * -pl->dir_x; return (0); } diff --git a/src/ft_detect.c b/src/ft_detect.c index bfc4449..10d7147 100644 --- a/src/ft_detect.c +++ b/src/ft_detect.c @@ -52,13 +52,13 @@ static void cl->rlist.x_side_dist = (cl->rlist.sqx + 1.0 - cl->rlist.x_ray_pos) * cl->rlist.x_delta_dist; } - ft_detection_init_y(cl); } void ft_detect(t_cub *cl) { ft_detection_init_x(cl); + ft_detection_init_y(cl); cl->rlist.hit = 0; while (cl->rlist.hit == 0) { diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index ebcaf48..79c0ed2 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -13,6 +13,7 @@ #include <cub3d.h> #include <stdint.h> #include <math.h> +#include <stdio.h> int ft_left_key(t_cub *clist) @@ -29,6 +30,8 @@ int sav_plane_x = pl->plane_x; pl->plane_x = pl->plane_x * cos(rot_speed) - pl->plane_y * sin(rot_speed); pl->plane_y = sav_plane_x * sin(rot_speed) + pl->plane_y * cos(rot_speed); + printf("dir_x> %f\n", pl->dir_x); + printf("dir_y> %f\n", pl->dir_y); return (0); } @@ -47,6 +50,8 @@ int sav_plane_x = pl->plane_x; pl->plane_x = pl->plane_x * cos(-rot_speed) - pl->plane_y * sin(-rot_speed); pl->plane_y = sav_plane_x * sin(-rot_speed) + pl->plane_y * cos(-rot_speed); + printf("dir_x> %f\n", pl->dir_x); + printf("dir_y> %f\n", pl->dir_y); return (0); } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index fadb9db..a4446b3 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -55,7 +55,7 @@ void if (cl->rlist.wall_t < 0) cl->rlist.wall_t = 0; cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2; - if (cl->rlist.wall_b >= wl->y_size)\ + if (cl->rlist.wall_b >= wl->y_size) cl->rlist.wall_b = wl->y_size - 1; ft_draw_verline(cl, i, cl->rlist.wall_t - 1, cl->rlist.wall_b); i++; |