From 147c4e94c0d97e3631bf268ff76f998d2595f775 Mon Sep 17 00:00:00 2001 From: Etienne Rey-bethbeder Date: Fri, 5 May 2023 17:06:47 +0200 Subject: [PATCH] =?UTF-8?q?Cube3D=20Fonctionnelle,=20perpective,=20tout=20?= =?UTF-8?q?=C3=A7a=20tout=20=C3=A7a,=20il=20manque=20plus=20que=20les=20te?= =?UTF-8?q?xtures=20et=20la=20norme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/blue.png | Bin 0 -> 640 bytes assets/green.png | Bin 0 -> 631 bytes assets/purple.png | Bin 0 -> 642 bytes assets/red.png | Bin 0 -> 631 bytes game/dda.c | 11 +++++------ game/game.h | 29 ++--------------------------- game/init.c | 34 ++++++++++++++++++++++++++++++---- game/manage_keys.c | 10 +++++----- map/map.h | 1 - 9 files changed, 42 insertions(+), 43 deletions(-) create mode 100644 assets/blue.png create mode 100644 assets/green.png create mode 100644 assets/purple.png create mode 100644 assets/red.png diff --git a/assets/blue.png b/assets/blue.png new file mode 100644 index 0000000000000000000000000000000000000000..dec04703406e50c2375d419c1213756abd92ab25 GIT binary patch literal 640 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLH@YFt%hmI|q0=J1Z0v<)>xlq%tsQ zOst(~>v7mYqV4{&XP41c*uUs^xI3+@-bi<{CYjU!VOg>T=dRa66 zMCF>Idym$HX0Ivr|98m4F+T2*)mn+5hyzM09RUH(tf4nNF07lJr0D$IQ~v*i*V9id zov@n8t*^qm49}^WG0^>yY$jV(Wahv(%bEJmUeD;eYVcy vo^5*Vr?+;$I6)eT1wR&lwYJ^G{pKaJ=Pp)*hbyGBKsr5L{an^LB{Ts5l#~Og literal 0 HcmV?d00001 diff --git a/assets/green.png b/assets/green.png new file mode 100644 index 0000000000000000000000000000000000000000..6c0cf5fc60df2d24fa9ab9039ff6f08eb79de976 GIT binary patch literal 631 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLH@YFt%hmI|q0=J1Z0v<)>xlq%tsQ zOst(~>v7mYqV4{&XP41c*uUs^xI3+@-bi<{CYjU!VOg>T=dRa66 zMCF>Idym$HX0Ivr|98m4F+T2*)mn+5hyzM09RUH(tf4nNF07lJr0D$IQ~v*i*V9id zov@n8t*ACk`zGUi;dj5myNXRwy!ytX0u6{1-oD!M<^-lwN literal 0 HcmV?d00001 diff --git a/assets/purple.png b/assets/purple.png new file mode 100644 index 0000000000000000000000000000000000000000..2880f5fd1a6ec495c62b9fdd17045e75bbb21efe GIT binary patch literal 642 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLH@YFt%hmI|q0=J1Z0v<)>xlq%tsQ zOst(~>v7mYqV4{&XP41c*uUs^xI3+@-bi<{CYjU!VOg>T=dRa66 zMCF>Idym$HX0Ivr|98m4F+T2*)mn+5hyzM09RUH(tf4nNF07lJr0D$IQ~v*i*V9id zov@n8t*GgE=b6Mw<&;$ShxCUwf literal 0 HcmV?d00001 diff --git a/assets/red.png b/assets/red.png new file mode 100644 index 0000000000000000000000000000000000000000..fd33fdba9feac956abf7eb01f8f8f4ae46576881 GIT binary patch literal 631 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLH@YFt%hmI|q0=J1Z0v<)>xlq%tsQ zOst(~>v7mYqV4{&XP41c*uUs^xI3+@-bi<{CYjU!VOg>T=dRa66 zMCF>Idym$HX0Ivr|98m4F+T2*)mn+5hyzM09RUH(tf4nNF07lJr0D$IQ~v*i*V9id zov@n8t*6;oL)e3?G>zx-?f(&*{x=d#Wzp$Py)NC3Y8 literal 0 HcmV?d00001 diff --git a/game/dda.c b/game/dda.c index 8df73c7..296c096 100644 --- a/game/dda.c +++ b/game/dda.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/02 15:49:00 by erey-bet #+# #+# */ -/* Updated: 2023/05/04 14:37:21 by erey-bet ### ########.fr */ +/* Updated: 2023/05/05 15:54:46 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,7 +72,8 @@ void loop_dda(t_game *game, t_dda *dda) dda->side = 1; } if (dda->map_x < 0 || dda->map_y < 0 - || dda->map_x >= (int)game->map.size_x || dda->map_y >= (int)game->map.size_y) + || dda->map_y >= (int)game->map.size_y + || dda->map_x >= (int)ft_strlen(game->map.map[dda->map_y])) { dda->perp_wall_dist = 1e30; return ; @@ -107,15 +108,13 @@ unsigned int get_rgba(int r, int g, int b, int a) void draw_line(t_game *game, t_dda *dda, unsigned int color, int x) { int y; - unsigned int white; - white = 0xFFFFFFFF; y = 0; while (y < HEIGHT) { if (y < dda->draw_start) { - mlx_put_pixel(game->window, x, y, white); + mlx_put_pixel(game->window, x, y, game->map.color_bot); } else if (y >= dda->draw_start && y <= dda->draw_end) { @@ -123,7 +122,7 @@ void draw_line(t_game *game, t_dda *dda, unsigned int color, int x) } else if (y > dda->draw_end) { - mlx_put_pixel(game->window, x, y, white); + mlx_put_pixel(game->window, x, y, game->map.color_top); } y++; } diff --git a/game/game.h b/game/game.h index 87e30f4..e1c70b0 100644 --- a/game/game.h +++ b/game/game.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/26 15:29:34 by erey-bet #+# #+# */ -/* Updated: 2023/05/04 13:27:54 by erey-bet ### ########.fr */ +/* Updated: 2023/05/05 16:54:19 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,32 +17,6 @@ # include # include -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -# include -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ -/* FAUT REMOVE */ - - # define WIDTH 1920 # define HEIGHT 1080 # define MOVESPEED 0.10 @@ -86,6 +60,7 @@ typedef struct s_game { mlx_t *mlx; mlx_image_t *window; + mlx_image_t textures[4]; t_ply ply; t_map map; t_ray ray; diff --git a/game/init.c b/game/init.c index 694fa40..1c22bd9 100644 --- a/game/init.c +++ b/game/init.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/27 14:50:22 by erey-bet #+# #+# */ -/* Updated: 2023/05/04 14:34:47 by erey-bet ### ########.fr */ +/* Updated: 2023/05/05 17:05:49 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,18 @@ void init_ply(t_map map, t_ply *ply) { ply->pos_x = map.ply_x; ply->pos_y = map.ply_y; - ply->dir_x = -1; + ply->dir_x = 0; ply->dir_y = 0; - ply->pla_x = 0.66; - ply->pla_y = 0.66; + if (map.direction == 'N') + ply->dir_y = -1; + if (map.direction == 'S') + ply->dir_y = 1; + if (map.direction == 'E') + ply->dir_x = 1; + if (map.direction == 'W') + ply->dir_x = -1; + ply->pla_x = -(ply->dir_y) * 0.66; + ply->pla_y = (ply->dir_x) * 0.66; } void init_ray(t_ray *ray) @@ -28,6 +36,23 @@ void init_ray(t_ray *ray) ray->dir_y = 0; } +int init_textures(t_map map, mlx_image_t **textures) +{ + (*textures)[0] = mlx_load_png(map.img_path[0]); + if (!textures[0]) + return (1); + (*textures)[1] = mlx_load_png(map.img_path[1]); + if (!textures[1]) + return (1); + (*textures)[2] = mlx_load_png(map.img_path[2]); + if (!textures[2]) + return (1); + (*textures)[3] = mlx_load_png(map.img_path[3]); + if (!textures[3]) + return (1); + return (0); +} + void init(t_map map, t_game *game) { game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili", true); @@ -36,4 +61,5 @@ void init(t_map map, t_game *game) game->map = map; init_ply(map, &game->ply); init_ray(&game->ray); + init_textures(map, &game->textures); } diff --git a/game/manage_keys.c b/game/manage_keys.c index 4963b1d..2c9c176 100644 --- a/game/manage_keys.c +++ b/game/manage_keys.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/27 14:14:51 by erey-bet #+# #+# */ -/* Updated: 2023/05/04 14:16:06 by erey-bet ### ########.fr */ +/* Updated: 2023/05/05 15:00:40 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ void rotate(t_ply *ply, bool right) old_plane_x = ply->pla_x; old_plane_y = ply->pla_y; speed = ROTATIONSPEED * (M_1_PI / 180.0); - if (right) + if (!right) speed = -speed; ply->dir_x = old_dir_x * cos(speed) - old_dir_y * sin(speed); ply->dir_y = old_dir_x * sin(speed) + old_dir_y * cos(speed); @@ -48,15 +48,15 @@ int manage_movement(t_game *game, int key) t_ply *ply; ply = &game->ply; - printf("dir_x: %f, dir_y: %f\n", ply->dir_x, ply->dir_y); + //printf("dir_x: %f, dir_y: %f\n", ply->dir_x, ply->dir_y); if (key == MLX_KEY_W) movement(game, ply, (ply->dir_x * MOVESPEED), (ply->dir_y * MOVESPEED)); else if (key == MLX_KEY_S) movement(game, ply, -(ply->dir_x * MOVESPEED), -(ply->dir_y * MOVESPEED)); else if (key == MLX_KEY_D) - movement(game, ply, -(ply->dir_x * MOVESPEED), (ply->dir_y * MOVESPEED)); + movement(game, ply, (ply->pla_x * MOVESPEED), (ply->pla_y * MOVESPEED)); else if (key == MLX_KEY_A) - movement(game, ply, (ply->dir_x * MOVESPEED), -(ply->dir_y * MOVESPEED)); + movement(game, ply, -(ply->pla_x * MOVESPEED), -(ply->pla_y * MOVESPEED)); else if (key == MLX_KEY_L) rotate(ply, true); else if (key == MLX_KEY_J) diff --git a/map/map.h b/map/map.h index 1640cb7..acd956c 100644 --- a/map/map.h +++ b/map/map.h @@ -7,7 +7,6 @@ typedef struct s_map { char **map; - void *img[4]; void *img_path[4]; long long color_bot; long long color_top;