diff --git a/Makefile b/Makefile index 752b77c..1418125 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: whaffman +#+ # # +#+ # # Created: 2024/10/15 11:48:46 by whaffman #+# #+# # -# Updated: 2025/05/08 23:15:13 by whaffman ######## odam.nl # +# Updated: 2025/05/11 13:26:58 by whaffman ######## odam.nl # # # # **************************************************************************** # @@ -27,7 +27,7 @@ MLX42_PATH = $(LIB_PATH)/MLX42 MLX42_INC_PATH = $(MLX42_PATH)/include/MLX42 MLX42 = $(MLX42_PATH)/build/libmlx42.a -CC = clang +CC = cc RM = rm -rf INCLUDES = -I./$(INC_PATH) -I./$(LIBFT_INC_PATH) -I./$(MLX42_INC_PATH) diff --git a/assets/overlay.xcf b/assets/overlay.xcf new file mode 100644 index 0000000..0ff61ac Binary files /dev/null and b/assets/overlay.xcf differ diff --git a/assets/overlay2.png b/assets/overlay2.png new file mode 100644 index 0000000..2ddae1e Binary files /dev/null and b/assets/overlay2.png differ diff --git a/assets/overlay2.xcf b/assets/overlay2.xcf new file mode 100644 index 0000000..8008d1d Binary files /dev/null and b/assets/overlay2.xcf differ diff --git a/inc/vec_math.h b/inc/vec_math.h index b213c92..20a83b2 100644 --- a/inc/vec_math.h +++ b/inc/vec_math.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* vec_math.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/25 10:11:44 by whaffman #+# #+# */ -/* Updated: 2025/05/06 15:20:37 by qmennen ### ########.fr */ +/* :::::::: */ +/* vec_math.h :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/04/25 10:11:44 by whaffman #+# #+# */ +/* Updated: 2025/05/11 13:36:45 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -93,4 +93,13 @@ t_vec2 rot(t_vec2 a, double angle); */ t_vec2 perp(t_vec2 a); +/** + * @brief Rotates a 2D vector by a given direction vector. + * + * @param vec The 2D vector to rotate. + * @param dir The direction vector to rotate by. + * @return The rotated vector as a new 2D vector. + */ +t_vec2 rot_by_dir(t_vec2 vec, t_vec2 dir, t_vec2 axis); + #endif // VEC_MATH_H \ No newline at end of file diff --git a/src/math/rot_by_dir.c b/src/math/rot_by_dir.c new file mode 100644 index 0000000..3af850f --- /dev/null +++ b/src/math/rot_by_dir.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* rot_by_dir.c :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/05/11 13:24:34 by whaffman #+# #+# */ +/* Updated: 2025/05/11 13:38:30 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" +t_vec2 rot_by_dir(t_vec2 vec, t_vec2 dir, t_vec2 axis) +{ + const double sin_angle = dir.x; + const double cos_angle = -dir.y; + t_vec2 rotated_vec; + + rotated_vec.x = axis.x + (vec.x - axis.x) * cos_angle - (vec.y - axis.y) * sin_angle; + rotated_vec.y = axis.y + (vec.x - axis.x) * sin_angle + (vec.y - axis.y) * cos_angle; + return (rotated_vec); +} diff --git a/src/render/render_minimap.c b/src/render/render_minimap.c index 7e9103d..a4137b9 100644 --- a/src/render/render_minimap.c +++ b/src/render/render_minimap.c @@ -1,7 +1,7 @@ #include "cub3d.h" -#define MINIMAP_SIZE 200 +#define MINIMAP_SIZE 300 void render_map(t_game *game) { t_vec2_int disp; @@ -26,6 +26,8 @@ void render_map(t_game *game) } map.x = ((double)disp.x/TILE_SIZE) + game->player->pos.x - (0.5 * MINIMAP_SIZE/TILE_SIZE); map.y = ((double)disp.y/TILE_SIZE) + game->player->pos.y - (0.5 * MINIMAP_SIZE/TILE_SIZE); + map = rot_by_dir(map, game->player->dir, game->player->pos); + if (map.x < 0 || map.x >= game->map->width || map.y < 0 || map.y >= game->map->height) { diff --git a/src/render/render_sprite.c b/src/render/render_sprite.c index 798db10..0f40710 100644 --- a/src/render/render_sprite.c +++ b/src/render/render_sprite.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */ -/* Updated: 2025/05/09 15:13:05 by whaffman ######## odam.nl */ +/* Updated: 2025/05/11 13:26:18 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -101,10 +101,10 @@ static void cam_fraction(t_game *game, t_sprite *sprite) } unsigned int calculate_alpha(mlx_texture_t *texture, int x, int y, double dist) { - int index; + // int index; int alpha; - index = (x + y * texture->width) * texture->bytes_per_pixel; + // index = (x + y * texture->width) * texture->bytes_per_pixel; dist = (dist > 1) * dist + (dist <= 1) * 1; alpha = (255.0 / dist); return (alpha); diff --git a/src/screen.c b/src/screen.c index 68eb603..416b11b 100644 --- a/src/screen.c +++ b/src/screen.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */ -/* Updated: 2025/05/09 15:27:37 by whaffman ######## odam.nl */ +/* Updated: 2025/05/11 14:04:28 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -78,7 +78,7 @@ int screen_display(t_screen *screen) printf(RED"Failed to display buffer image\n"RESET); return (FAILURE); } - if (mlx_image_to_window(screen->mlx, screen->minimap, 200, 200) < 0) + if (mlx_image_to_window(screen->mlx, screen->minimap, 175, 575) < 0) { printf(RED"Failed to display buffer image\n"RESET); return (FAILURE); diff --git a/src/util/initialize.c b/src/util/initialize.c index 82d84fb..1e32ffc 100644 --- a/src/util/initialize.c +++ b/src/util/initialize.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */ -/* Updated: 2025/05/09 13:07:25 by whaffman ######## odam.nl */ +/* Updated: 2025/05/11 14:03:16 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -68,7 +68,7 @@ static int init_temp(t_game **game) (*game)->map->sprites[9].dist = 0; (*game)->map->sprites[9].texture = mlx_load_png("./assets/lamp.png"); (*game)->map->n_sprites = 10; - (*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx, mlx_load_png("./assets/overlay.png")); + (*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx, mlx_load_png("./assets/overlay2.png")); return (SUCCESS); }