From 3bfe34eee0c52567902985ee30801818c6181e28 Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Thu, 22 May 2025 14:49:11 +0200 Subject: [PATCH] visiting tiles --- Makefile | 5 +- README.md | 14 +++++- inc/cub3d.h | 15 +++--- inc/player.h | 15 +++--- inc/render.h | 21 +++----- src/game.c | 19 ++++---- src/main.c | 14 +++--- src/map/map_create.c | 16 +++---- src/moves.c | 34 ++++++++++--- src/parser/parse_map.c | 14 +++--- src/player.c | 26 +++------- src/render/render.c | 67 +++----------------------- src/render/render_clear.c | 23 --------- src/render/render_line.c | 95 ------------------------------------- src/render/render_minimap.c | 16 ++++--- src/util/initialize.c | 14 +++--- 16 files changed, 125 insertions(+), 283 deletions(-) delete mode 100644 src/render/render_clear.c delete mode 100644 src/render/render_line.c diff --git a/Makefile b/Makefile index 18e5001..217d1d4 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,7 @@ SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c")) BUILD_CONFIGS = release debug asan tsan release_CFLAGS = -Wall -Werror -Werror -flto -Ofast -march=native -mtune=native -ffast-math +unity_CFLAGS = -Wall -Werror -Werror -Ofast -march=native -mtune=native -ffast-math debug_CFLAGS = -Wall -Werror -Werror -g3 -DDEBUG -DDBG='fprintf(stderr, RED "DEBUG: " RESET "%s:%d (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);' asan_CFLAGS = -Wall -Werror -Werror -fsanitize=address,leak,undefined -g3 tsan_CFLAGS = -Wall -Werror -Werror -fsanitize=thread -g3 @@ -103,8 +104,8 @@ unity: $(BUILD_PATH)/unity/$(NAME) $(BUILD_PATH)/unity/$(NAME): $(BUILD_PATH)/unity/blob.c $(LIBFT) $(MLX42) $(ALL_SOURCES) $(info $(bold)$(green)Building unity blob$(reset)) - $(CC) $(release_CFLAGS) $(INCLUDES) -Isrc -MMD -MP -c $(BUILD_PATH)/unity/blob.c -o $(BUILD_PATH)/unity/blob.o - $(CC) $(release_CFLAGS) $(INCLUDES) -o $@ $(BUILD_PATH)/unity/blob.o $(LDLIBS) + $(CC) $(unity_CFLAGS) $(INCLUDES) -Isrc -MMD -MP -c $(BUILD_PATH)/unity/blob.c -o $(BUILD_PATH)/unity/blob.o + $(CC) $(unity_CFLAGS) $(INCLUDES) -o $@ $(BUILD_PATH)/unity/blob.o $(LDLIBS) $(BUILD_PATH)/unity/blob.c: $(ALL_SOURCES) $(BUILD_PATH)/unity diff --git a/README.md b/README.md index 263a43b..efeb187 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,17 @@ # Cub3d (by Quinten & Willem) -- Modules - - +## TODO +- [ ] **Config Parsing:** support inclusion of sprites in the format (-{type: c, s} {identifier} {path}) +- [ ] **Map Parsing:** Keep in mind the possible addition of sprites / collectibles +- [ ] **Gameplay:** Allow sprites to be collected (stopping them from being rendered) +- [ ] **Rendering:** Allow for either floor/ceiling textures *or* colors. +- [ ] **Gameplay:** Implement doors/exits +- [ ] **UX:** Allow user to capture moues and use it for looking. Also allow capture release. +- [ ] **UX:** Title / end screen +- [ ] **Map Design:** Design a map for captivating gameplay. + +## Gameplay +- Your on surveillance and you need - External functions - open diff --git a/inc/cub3d.h b/inc/cub3d.h index 4be7300..98870f9 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* cub3d.h :+: :+: */ -/* +:+ */ -/* By: qmennen +#+ */ -/* +#+ */ -/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */ -/* Updated: 2025/05/16 15:01:40 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* cub3d.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */ +/* Updated: 2025/05/22 14:05:24 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,5 +56,6 @@ # include "texture.h" int initialize_cub3d(t_game **game, const char *mapfile); +int shader_init(t_game **game); #endif diff --git a/inc/player.h b/inc/player.h index 5c7da6b..c930b22 100644 --- a/inc/player.h +++ b/inc/player.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* player.h :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/15 18:53:27 by qmennen #+# #+# */ -/* Updated: 2025/05/15 13:28:11 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* player.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/15 18:53:27 by qmennen #+# #+# */ +/* Updated: 2025/05/22 13:57:05 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,6 @@ # include "cub3d.h" int player_create(t_game **game); -void player_render(t_screen *screen, t_player *player); void player_update(t_game *game, double delta_time); #endif diff --git a/inc/render.h b/inc/render.h index 6a30483..6eb32f5 100644 --- a/inc/render.h +++ b/inc/render.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* render.h :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */ -/* Updated: 2025/05/15 14:25:46 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* render.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */ +/* Updated: 2025/05/22 14:00:45 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,13 +15,6 @@ # include "cub3d.h" -int render_check_bounds(t_screen *screen, t_vec2 *point); -void render_line(t_screen *screen, - t_vec2 start, t_vec2 end, unsigned int color); -void render_circle(t_screen *screen, - t_vec2 point, int radius, unsigned int color); -void render_clear(t_screen *screen); -void render_entities(t_game *game); void render_map(t_game *game); t_render cast_ray(t_game *game, int x); void cast_rays(t_game *game); diff --git a/src/game.c b/src/game.c index 12795c6..c0118a3 100644 --- a/src/game.c +++ b/src/game.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* game.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */ -/* Updated: 2025/05/16 15:01:28 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* game.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */ +/* Updated: 2025/05/22 14:03:26 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,15 +52,14 @@ void game_loop(void *param) fprintf(stderr, "FPS: %d\n", fps / 20); fps = 0; } - render_clear(game->screen); player_update(game, delta_time); cast_rays(game); render_map(game); keyboard_update(game); if (game->player->is_moving) { - game->screen->img->instances[0].x = sin(game->framecount / 4.0) * 20; - game->screen->img->instances[0].y = cos(game->framecount / 2.0) * 10; + game->screen->img->instances[0].x = sin(game->framecount / 6.0) * 20; + game->screen->img->instances[0].y = cos(game->framecount / 3.0) * 10; } } diff --git a/src/main.c b/src/main.c index 592b56a..360d3b5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* main.c :+: :+: */ -/* +:+ */ -/* By: qmennen +#+ */ -/* +#+ */ -/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */ -/* Updated: 2025/05/06 14:17:33 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */ +/* Updated: 2025/05/22 14:06:24 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/map/map_create.c b/src/map/map_create.c index 90b01e0..3a4995a 100644 --- a/src/map/map_create.c +++ b/src/map/map_create.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* map_create.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/23 12:21:13 by whaffman #+# #+# */ -/* Updated: 2025/05/14 20:24:32 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* map_create.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/23 12:21:13 by whaffman #+# #+# */ +/* Updated: 2025/05/22 14:16:54 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,7 +54,7 @@ static int map_validate_and_finalize(t_game **game, t_tile **grid) } grid_free((*game)->map->grid, (*game)->map->height); (*game)->map->grid = grid; - print_config((*game)->map); + //print_config((*game)->map); return (SUCCESS); } diff --git a/src/moves.c b/src/moves.c index eec4f0d..da12fcd 100644 --- a/src/moves.c +++ b/src/moves.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* moves.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */ -/* Updated: 2025/05/14 20:14:24 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* moves.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */ +/* Updated: 2025/05/22 14:47:58 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,9 +56,29 @@ static void rotate(t_player *player, double rot_speed, double delta) player->camera = rot(player->camera, rot_speed * delta); } +void visit_area(t_game *game) +{ + int i; + int x; + int y; + + i = 0; + while (i < 9) + { + x = game->player->pos.x + (i % 3) - 1; + y = game->player->pos.y + (i / 3) - 1; + if (get_tile(game->map, x, y) == TILE_EMPTY) + { + game->map->grid[y][x] = TILE_VISITED; + } + i++; + } +} + void player_update(t_game *game, double delta_time) { game->player->is_moving = 0; + visit_area(game); if (get_key(game, MLX_KEY_W)) move(game->map, game->player, 1, delta_time); else if (get_key(game, MLX_KEY_S)) diff --git a/src/parser/parse_map.c b/src/parser/parse_map.c index 06acc5e..e13c20c 100644 --- a/src/parser/parse_map.c +++ b/src/parser/parse_map.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* parse_map.c :+: :+: */ -/* +:+ */ -/* By: qmennen +#+ */ -/* +#+ */ -/* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */ -/* Updated: 2025/05/15 13:19:05 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* parse_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */ +/* Updated: 2025/05/22 14:01:24 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/player.c b/src/player.c index f49398b..72cd4a0 100644 --- a/src/player.c +++ b/src/player.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* player.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */ -/* Updated: 2025/05/15 13:15:36 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* player.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */ +/* Updated: 2025/05/22 13:57:00 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,15 +26,3 @@ int player_create(t_game **game) (*game)->player = player; return (SUCCESS); } - -void player_render(t_screen *screen, t_player *player) -{ - t_vec2 direction; - - if (player->pos.x < 0 || player->pos.x >= screen->width - || player->pos.y < 0 || player->pos.y >= screen->height) - return ; - render_circle(screen, mul(player->pos, TILE_SIZE), 4, 0x111111ff); - direction = add(mul(player->pos, TILE_SIZE), mul(player->dir, TILE_SIZE)); - render_line(screen, mul(player->pos, TILE_SIZE), direction, 0xa83232ff); -} diff --git a/src/render/render.c b/src/render/render.c index 49a72dd..a0e9b31 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -1,70 +1,17 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* render.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/15 16:28:10 by qmennen #+# #+# */ -/* Updated: 2025/05/14 19:28:47 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* render.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/15 16:28:10 by qmennen #+# #+# */ +/* Updated: 2025/05/22 13:59:32 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" -int render_check_bounds(t_screen *screen, t_vec2 *point) -{ - return (point->x >= 0 - && point->x < screen->width - && point->y > 0 - && point->y < screen->height); -} - -void render_tile(t_screen *screen, int x, int y, t_tile tile) -{ - int i; - int xp; - int yp; - - i = 0; - if (tile < 0) - return ; - while ((i++) < TILE_SIZE * TILE_SIZE) - { - xp = x + (i % TILE_SIZE); - yp = y + (i / TILE_SIZE); - if (xp < 0 || xp >= screen->width || yp < 0 || yp >= screen->height) - continue ; - if (tile == TILE_WALL) - mlx_put_pixel(screen->minimap, xp, yp, 0xA88132aa); - else if (tile == TILE_EMPTY || tile == TILE_PLAYER) - mlx_put_pixel(screen->minimap, xp, yp, 0xaaaaaa44); - } -} - -void render_map2(t_screen *screen, t_map *map) -{ - int i; - int x; - int y; - - i = 0; - while (i < map->width * map->height) - { - x = i % map->width; - y = i / map->width; - if (x < 0 || x >= map->width || y < 0 || y >= map->height) - continue ; - render_tile(screen, x * TILE_SIZE, y * TILE_SIZE, map->grid[y][x]); - i++; - } -} - -void render_entities(t_game *game) -{ - player_render(game->screen, game->player); -} - void cast_rays(t_game *game) { int x; diff --git a/src/render/render_clear.c b/src/render/render_clear.c deleted file mode 100644 index 460d905..0000000 --- a/src/render/render_clear.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* :::::::: */ -/* render_clear.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/17 20:05:51 by qmennen #+# #+# */ -/* Updated: 2025/05/07 11:37:36 by whaffman ######## odam.nl */ -/* */ -/* ************************************************************************** */ - -#include "render.h" - -void render_clear(t_screen *screen) -{ - int i; - - i = 0; - while (i++ < screen->width * screen->height) - mlx_put_pixel(screen->minimap, - i % screen->width, i / screen->width, 0x0); -} diff --git a/src/render/render_line.c b/src/render/render_line.c deleted file mode 100644 index 0ca09d8..0000000 --- a/src/render/render_line.c +++ /dev/null @@ -1,95 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* :::::::: */ -/* render_line.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/17 20:06:40 by qmennen #+# #+# */ -/* Updated: 2025/05/07 11:36:57 by whaffman ######## odam.nl */ -/* */ -/* ************************************************************************** */ - -#include "render.h" - -static void line_low(t_screen *screen, - t_vec2 start, t_vec2 end, unsigned int color) -{ - int delta; - int yi; - t_vec2 cur; - t_vec2 delta_point; - - delta_point.x = end.x - start.x; - delta_point.y = abs((int) end.y - (int) start.y); - yi = 1; - if (end.y - start.y < 0) - yi = -1; - delta = 2 * delta_point.y - delta_point.x; - cur = start; - while (cur.x <= end.x) - { - if (render_check_bounds(screen, &cur)) - mlx_put_pixel(screen->minimap, (int)cur.x, (int)cur.y, color); - if (delta > 0) - { - cur.y += yi; - delta -= 2 * delta_point.x; - } - delta += 2 * delta_point.y; - cur.x++; - } -} - -static void line_high(t_screen *screen, - t_vec2 start, t_vec2 end, unsigned int color) -{ - int delta; - int xi; - t_vec2 cur; - t_vec2 delta_point; - - delta_point.x = abs((int) end.x - (int) start.x); - delta_point.y = end.y - start.y; - xi = 1; - if (end.x - start.x < 0) - xi = -1; - delta = 2 * delta_point.x - delta_point.y; - cur = start; - while (cur.y <= end.y) - { - if (render_check_bounds(screen, &cur)) - mlx_put_pixel(screen->minimap, (int)cur.x, (int)cur.y, color); - if (delta > 0) - { - cur.x += xi; - delta -= 2 * delta_point.y; - } - delta += 2 * delta_point.x; - cur.y++; - } -} - -void render_line(t_screen *screen, - t_vec2 start, t_vec2 end, unsigned int color) -{ - if ((start.x < 0 || start.x >= (int) screen->img->width - || start.y < 0 || start.y >= (int) screen->img->height) - && (end.x < 0 || end.x >= (int) screen->img->width - || end.y < 0 || end.y >= (int) screen->img->height)) - return ; - if (abs((int) end.y - (int) start.y) < abs((int) end.x - (int) start.x)) - { - if (start.x > end.x) - line_low(screen, end, start, color); - else - line_low(screen, start, end, color); - } - else - { - if (start.y > end.y) - line_high(screen, end, start, color); - else - line_high(screen, start, end, color); - } -} diff --git a/src/render/render_minimap.c b/src/render/render_minimap.c index 7816f03..24aa6b7 100644 --- a/src/render/render_minimap.c +++ b/src/render/render_minimap.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* render_minimap.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/05/12 11:31:34 by whaffman #+# #+# */ -/* Updated: 2025/05/18 12:57:16 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* render_minimap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/12 11:31:34 by whaffman #+# #+# */ +/* Updated: 2025/05/22 14:45:12 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,8 @@ static void draw_minimap_pixel(t_game *game, t_vec2_int disp, t_vec2 map) else if (game->map->grid[(int)map.y][(int)map.x] == TILE_EMPTY || game->map->grid[(int)map.y][(int)map.x] == TILE_PLAYER) mlx_put_pixel(img, disp.x, disp.y, 0x00ff0077); + else if (game->map->grid[(int)map.y][(int)map.x] == TILE_VISITED) + mlx_put_pixel(img, disp.x, disp.y, 0xaaff0077); else mlx_put_pixel(img, disp.x, disp.y, 0x00ff0044); } diff --git a/src/util/initialize.c b/src/util/initialize.c index e6c5259..9f98e32 100644 --- a/src/util/initialize.c +++ b/src/util/initialize.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* initialize.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */ -/* Updated: 2025/05/15 17:09:38 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* initialize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */ +/* Updated: 2025/05/22 14:06:29 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */