diff --git a/assets/blue.png b/assets/blue.png new file mode 100644 index 0000000..dec0470 Binary files /dev/null and b/assets/blue.png differ diff --git a/assets/green.png b/assets/green.png new file mode 100644 index 0000000..6c0cf5f Binary files /dev/null and b/assets/green.png differ diff --git a/assets/purple.png b/assets/purple.png new file mode 100644 index 0000000..2880f5f Binary files /dev/null and b/assets/purple.png differ diff --git a/assets/red.png b/assets/red.png new file mode 100644 index 0000000..fd33fdb Binary files /dev/null and b/assets/red.png differ 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;