visiting tiles
This commit is contained in:
parent
f8019acf7d
commit
3bfe34eee0
5
Makefile
5
Makefile
@ -46,6 +46,7 @@ SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c"))
|
|||||||
BUILD_CONFIGS = release debug asan tsan
|
BUILD_CONFIGS = release debug asan tsan
|
||||||
|
|
||||||
release_CFLAGS = -Wall -Werror -Werror -flto -Ofast -march=native -mtune=native -ffast-math
|
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__);'
|
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
|
asan_CFLAGS = -Wall -Werror -Werror -fsanitize=address,leak,undefined -g3
|
||||||
tsan_CFLAGS = -Wall -Werror -Werror -fsanitize=thread -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)
|
$(BUILD_PATH)/unity/$(NAME): $(BUILD_PATH)/unity/blob.c $(LIBFT) $(MLX42) $(ALL_SOURCES)
|
||||||
$(info $(bold)$(green)Building unity blob$(reset))
|
$(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) $(unity_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) -o $@ $(BUILD_PATH)/unity/blob.o $(LDLIBS)
|
||||||
|
|
||||||
|
|
||||||
$(BUILD_PATH)/unity/blob.c: $(ALL_SOURCES) $(BUILD_PATH)/unity
|
$(BUILD_PATH)/unity/blob.c: $(ALL_SOURCES) $(BUILD_PATH)/unity
|
||||||
|
|||||||
14
README.md
14
README.md
@ -1,7 +1,17 @@
|
|||||||
# Cub3d (by Quinten & Willem)
|
# 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
|
- External functions
|
||||||
- open
|
- open
|
||||||
|
|||||||
13
inc/cub3d.h
13
inc/cub3d.h
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* cub3d.h :+: :+: */
|
/* cub3d.h :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
|
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/16 15:01:40 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/22 14:05:24 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -56,5 +56,6 @@
|
|||||||
# include "texture.h"
|
# include "texture.h"
|
||||||
|
|
||||||
int initialize_cub3d(t_game **game, const char *mapfile);
|
int initialize_cub3d(t_game **game, const char *mapfile);
|
||||||
|
int shader_init(t_game **game);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
13
inc/player.h
13
inc/player.h
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* player.h :+: :+: */
|
/* player.h :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 18:53:27 by qmennen #+# #+# */
|
/* Created: 2025/04/15 18:53:27 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/15 13:28:11 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/22 13:57:05 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,7 +16,6 @@
|
|||||||
# include "cub3d.h"
|
# include "cub3d.h"
|
||||||
|
|
||||||
int player_create(t_game **game);
|
int player_create(t_game **game);
|
||||||
void player_render(t_screen *screen, t_player *player);
|
|
||||||
void player_update(t_game *game, double delta_time);
|
void player_update(t_game *game, double delta_time);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
19
inc/render.h
19
inc/render.h
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* render.h :+: :+: */
|
/* render.h :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */
|
/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/15 14:25:46 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/22 14:00:45 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,13 +15,6 @@
|
|||||||
|
|
||||||
# include "cub3d.h"
|
# 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);
|
void render_map(t_game *game);
|
||||||
t_render cast_ray(t_game *game, int x);
|
t_render cast_ray(t_game *game, int x);
|
||||||
void cast_rays(t_game *game);
|
void cast_rays(t_game *game);
|
||||||
|
|||||||
17
src/game.c
17
src/game.c
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* game.c :+: :+: */
|
/* game.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/16 15:01:28 by whaffman ######## odam.nl */
|
/* 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);
|
fprintf(stderr, "FPS: %d\n", fps / 20);
|
||||||
fps = 0;
|
fps = 0;
|
||||||
}
|
}
|
||||||
render_clear(game->screen);
|
|
||||||
player_update(game, delta_time);
|
player_update(game, delta_time);
|
||||||
cast_rays(game);
|
cast_rays(game);
|
||||||
render_map(game);
|
render_map(game);
|
||||||
keyboard_update(game);
|
keyboard_update(game);
|
||||||
if (game->player->is_moving)
|
if (game->player->is_moving)
|
||||||
{
|
{
|
||||||
game->screen->img->instances[0].x = sin(game->framecount / 4.0) * 20;
|
game->screen->img->instances[0].x = sin(game->framecount / 6.0) * 20;
|
||||||
game->screen->img->instances[0].y = cos(game->framecount / 2.0) * 10;
|
game->screen->img->instances[0].y = cos(game->framecount / 3.0) * 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/main.c
12
src/main.c
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* main.c :+: :+: */
|
/* main.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/06 14:17:33 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/22 14:06:24 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* map_create.c :+: :+: */
|
/* map_create.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/23 12:21:13 by whaffman #+# #+# */
|
/* Created: 2025/04/23 12:21:13 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/05/14 20:24:32 by whaffman ######## odam.nl */
|
/* 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);
|
grid_free((*game)->map->grid, (*game)->map->height);
|
||||||
(*game)->map->grid = grid;
|
(*game)->map->grid = grid;
|
||||||
print_config((*game)->map);
|
//print_config((*game)->map);
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
32
src/moves.c
32
src/moves.c
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* moves.c :+: :+: */
|
/* moves.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */
|
/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/05/14 20:14:24 by whaffman ######## odam.nl */
|
/* 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);
|
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)
|
void player_update(t_game *game, double delta_time)
|
||||||
{
|
{
|
||||||
game->player->is_moving = 0;
|
game->player->is_moving = 0;
|
||||||
|
visit_area(game);
|
||||||
if (get_key(game, MLX_KEY_W))
|
if (get_key(game, MLX_KEY_W))
|
||||||
move(game->map, game->player, 1, delta_time);
|
move(game->map, game->player, 1, delta_time);
|
||||||
else if (get_key(game, MLX_KEY_S))
|
else if (get_key(game, MLX_KEY_S))
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* parse_map.c :+: :+: */
|
/* parse_map.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */
|
/* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/05/15 13:19:05 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/22 14:01:24 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
24
src/player.c
24
src/player.c
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* player.c :+: :+: */
|
/* player.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */
|
/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/15 13:15:36 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/22 13:57:00 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,15 +26,3 @@ int player_create(t_game **game)
|
|||||||
(*game)->player = player;
|
(*game)->player = player;
|
||||||
return (SUCCESS);
|
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);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,70 +1,17 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* render.c :+: :+: */
|
/* render.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 16:28:10 by qmennen #+# #+# */
|
/* Created: 2025/04/15 16:28:10 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/14 19:28:47 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/22 13:59:32 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "cub3d.h"
|
#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)
|
void cast_rays(t_game *game)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* :::::::: */
|
|
||||||
/* render_clear.c :+: :+: */
|
|
||||||
/* +:+ */
|
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
|
||||||
/* +#+ */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
@ -1,95 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* :::::::: */
|
|
||||||
/* render_line.c :+: :+: */
|
|
||||||
/* +:+ */
|
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
|
||||||
/* +#+ */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* render_minimap.c :+: :+: */
|
/* render_minimap.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/12 11:31:34 by whaffman #+# #+# */
|
/* Created: 2025/05/12 11:31:34 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/05/18 12:57:16 by whaffman ######## odam.nl */
|
/* 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
|
else if (game->map->grid[(int)map.y][(int)map.x] == TILE_EMPTY
|
||||||
|| game->map->grid[(int)map.y][(int)map.x] == TILE_PLAYER)
|
|| game->map->grid[(int)map.y][(int)map.x] == TILE_PLAYER)
|
||||||
mlx_put_pixel(img, disp.x, disp.y, 0x00ff0077);
|
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
|
else
|
||||||
mlx_put_pixel(img, disp.x, disp.y, 0x00ff0044);
|
mlx_put_pixel(img, disp.x, disp.y, 0x00ff0044);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* initialize.c :+: :+: */
|
/* initialize.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
|
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/15 17:09:38 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/22 14:06:29 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user