Browse Source

add: larger window

master
narnaud 3 years ago
parent
commit
fe6ddc07e6
  1. 4
      includes/cub3d.h
  2. 26
      sources/main.c
  3. 20
      sources/render.c

4
includes/cub3d.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

26
sources/main.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

20
sources/render.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)

Loading…
Cancel
Save