From fe6ddc07e64d0cd2f5d40ad4768785eebcb840ea Mon Sep 17 00:00:00 2001 From: narnaud Date: Tue, 31 May 2022 18:13:03 +0200 Subject: [PATCH] add: larger window --- includes/cub3d.h | 4 ++-- sources/main.c | 26 ++++++++++++++++++-------- sources/render.c | 20 ++++++++++++-------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/includes/cub3d.h b/includes/cub3d.h index 55ec492..5ede39c 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */ -/* Updated: 2022/05/31 13:36:06 by narnaud ### ########.fr */ +/* Updated: 2022/05/31 16:17:03 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ # define DEBUG 0 # endif -# define WIN_X_SZ 900 +# define WIN_X_SZ 1760 # define WIN_Y_SZ 900 # define BUFFER_SIZE 4096 diff --git a/sources/main.c b/sources/main.c index 7bf73e9..45c2443 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */ -/* Updated: 2022/05/31 15:09:14 by narnaud ### ########.fr */ +/* Updated: 2022/05/31 17:13:28 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,17 +30,22 @@ void init_window(t_env *env) int key_hook_primary(int keycode, void *param) { t_env *env; - static t_vec_d new_pos; env = (t_env *)param; if (keycode == KEY_ARROW_UP) - set_vec(&new_pos, env->playerPos.x + env->playerDir.x, env->playerPos.y + env->playerDir.y); + { + if (env->map[(int)env->playerPos.y][(int)(env->playerPos.x + env->playerDir.x / 5)] == '0') + set_vec(&env->playerPos, env->playerPos.x + env->playerDir.x / 5, env->playerPos.y); + if (env->map[(int)(env->playerPos.y + env->playerDir.y / 5)][(int)env->playerPos.x] == '0') + set_vec(&env->playerPos, env->playerPos.x, env->playerPos.y + env->playerDir.y / 5); + } else if (keycode == KEY_ARROW_DOWN) - set_vec(&new_pos, env->playerPos.x - env->playerDir.x, env->playerPos.y - env->playerDir.y); - if (env->map[(int)floor(new_pos.y)][(int)floor(new_pos.x)] == '0') - env->playerPos = new_pos; - else - new_pos = env->playerPos; + { + if (env->map[(int)env->playerPos.y][(int)(env->playerPos.x - env->playerDir.x / 5)] == '0') + set_vec(&env->playerPos, env->playerPos.x - env->playerDir.x / 5, env->playerPos.y); + if (env->map[(int)(env->playerPos.y - env->playerDir.y / 5)][(int)env->playerPos.x] == '0') + set_vec(&env->playerPos, env->playerPos.x, env->playerPos.y - env->playerDir.y / 5); + } if (keycode == KEY_ARROW_LEFT) { set_vec(&env->playerDir, @@ -59,6 +64,11 @@ int key_hook_primary(int keycode, void *param) cos(M_PI / 9) * env->camPlan.x - sin(M_PI / 9) * env->camPlan.y, sin(M_PI / 9) * env->camPlan.x + cos(M_PI / 9) * env->camPlan.y); } + if (DEBUG) + { + printf("playerPos: %f, %f. playerDir: %f, %f\n", env->playerPos.x, env->playerPos.y, env->playerDir.x, env->playerDir.y); + printf("camPlan: %f, %f\n", env->camPlan.x, env->camPlan.y); + } render(env); return (1); } diff --git a/sources/render.c b/sources/render.c index 601454f..d7948e8 100644 --- a/sources/render.c +++ b/sources/render.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/31 09:33:02 by narnaud #+# #+# */ -/* Updated: 2022/05/31 13:46:43 by narnaud ### ########.fr */ +/* Updated: 2022/05/31 18:11:15 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,7 @@ void draw_vert(t_env *env, int x, int *startEnd, int color) } } -void draw_square(t_env *env, t_vec vec, int size, int color) +void draw_square(t_env *env, t_vec_d vec, int size, int color) { int step_x; int step_y; @@ -46,7 +46,10 @@ void draw_square(t_env *env, t_vec vec, int size, int color) step_x = 0; while (step_x < size) { - env->buffer[(env->line_bytes * (vec.y * size + step_y)) + (vec.x * size + step_x)] = color; + if (step_x == size - 1 || step_y == size - 1) + env->buffer[(env->line_bytes * (int)(vec.y * size + step_y)) + (int)(vec.x * size + step_x)] = 0; + else + env->buffer[(env->line_bytes * (int)(vec.y * size + step_y)) + (int)(vec.x * size + step_x)] = color; step_x++; } step_y++; @@ -57,6 +60,7 @@ void render_minimap(t_env *env) { char **map; t_vec vec; + t_vec_d vecd; vec.y = 0; map = env->map; @@ -65,17 +69,17 @@ void render_minimap(t_env *env) vec.x = 0; while (map[vec.y][vec.x]) { + vecd = (t_vec_d){vec.x, vec.y}; if (map[vec.y][vec.x] == '0') - draw_square(env, vec, 6, 39424); + draw_square(env, vecd, 6, 39424); else if (map[vec.y][vec.x] == '1') - draw_square(env, vec, 6, 11885067); + draw_square(env, vecd, 6, 11885067); vec.x++; } vec.y++; } - vec.x = round(env->playerPos.x); - vec.y = round(env->playerPos.y); - draw_square(env, vec, 6, 255); + vecd = (t_vec_d){env->playerPos.x, env->playerPos.y}; + draw_square(env, vecd, 6, 255); } double get_wall_dist(t_env *env, int x)