a lot of doors are opening rn

This commit is contained in:
Quinten Mennen 2025-06-04 18:43:28 +02:00
parent 483dca8711
commit ff649d01cc
15 changed files with 108 additions and 70 deletions

View File

@ -6,7 +6,7 @@
# By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
# Updated: 2025/06/03 21:48:38 by qmennen ### ########.fr #
# Updated: 2025/06/04 18:16:27 by qmennen ### ########.fr #
# #
# **************************************************************************** #

BIN
assets/door.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* player.h :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/15 18:53:27 by qmennen #+# #+# */
/* Updated: 2025/06/04 16:39:57 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* player.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 18:53:27 by qmennen #+# #+# */
/* Updated: 2025/06/04 18:42:25 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,5 +19,6 @@ int player_create(t_game **game);
void player_update(t_game *game, double delta_time);
void visit_area(t_game *game);
void rotate(t_player *player, double rot_speed, double delta);
void interact_door(t_game *game);
#endif

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* render.h :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */
/* Updated: 2025/06/03 14:47:34 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* render.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */
/* Updated: 2025/06/04 18:15:26 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,7 @@ void render_map(t_game *game);
t_render cast_ray(t_game *game, int x);
void cast_rays(t_game *game);
void render_sprites(t_render *render, t_game *game);
double dda(t_vec2 ray_dir, t_vec2 pos, t_map *map);
double dda(t_render *render, t_vec2 ray_dir, t_vec2 pos, t_map *map);
void draw_floor(t_game *game);
void draw_line(t_game *game, t_render render, int x);
unsigned int get_texture_color(mlx_texture_t *texture,

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
/* Updated: 2025/06/03 21:55:47 by qmennen ### ########.fr */
/* Updated: 2025/06/04 18:14:36 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,6 +22,8 @@ typedef enum TILE
TILE_EMPTY = 0,
TILE_WALL = 1,
TILE_PLAYER = 2,
TILE_DOOR = 3,
TILE_DOOR_OPEN = 4,
} t_tile;
typedef enum SPRITE_TYPE
@ -94,7 +96,7 @@ typedef struct s_map
t_tile **grid;
mlx_texture_t *texture_floor;
mlx_texture_t *texture_ceiling;
mlx_texture_t *textures[4];
mlx_texture_t *textures[5];
t_sprite *sprites;
t_sprite_lib *sprite_lib;
unsigned int n_sprites;
@ -134,6 +136,7 @@ typedef enum e_side
SIDE_SOUTH,
SIDE_WEST,
SIDE_EAST,
SIDE_DOOR,
} t_side;
typedef enum e_game_state
@ -146,6 +149,8 @@ typedef enum e_game_state
typedef struct s_render
{
double perp_dist;
int sign;
int door;
t_side side;
double wall_x;
} t_render;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
/* Updated: 2025/06/03 22:12:38 by qmennen ### ########.fr */
/* Updated: 2025/06/04 18:35:34 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -60,7 +60,7 @@ int collision_horizontal(t_map *map, t_player *player, double xa)
t_tile tile;
tile = get_tile(map, (int)((player->pos.x + xa)), (int)((player->pos.y)));
return (tile != TILE_WALL && tile != TILE_VOID);
return (tile != TILE_WALL && tile != TILE_VOID && tile != TILE_DOOR);
}
int collision_vertical(t_map *map, t_player *player, double ya)
@ -68,5 +68,5 @@ int collision_vertical(t_map *map, t_player *player, double ya)
t_tile tile;
tile = get_tile(map, (int)((player->pos.x)), (int)((player->pos.y + ya)));
return (tile != TILE_WALL && tile != TILE_VOID);
return (tile != TILE_WALL && tile != TILE_VOID && tile != TILE_DOOR);
}

View File

@ -6,18 +6,21 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/03 15:53:32 by qmennen #+# #+# */
/* Updated: 2025/06/03 22:18:26 by qmennen ### ########.fr */
/* Updated: 2025/06/04 18:42:45 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "game.h"
#include "cub3d.h"
void handle_flash(t_sprite *sprite, t_game *game)
{
if (game->screen->flash != 1)
return ;
if (sprite->type == SPRITE_TYPE_ENEMY && game->screen->flash == 1
&& sprite->dist < 2.0)
{
sprite->type = SPRITE_TYPE_DISABLED;
game->scoreboard->enemies++;
}
}

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* moves.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */
/* Updated: 2025/06/04 16:39:34 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* moves.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */
/* Updated: 2025/06/04 18:42:35 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -95,6 +95,7 @@ void player_update(t_game *game, double delta_time)
{
game->screen->flash = 3;
game->player->battery -= 0.1f;
interact_door(game);
}
if (game->player->hit_timer > 0)
game->player->hit_timer -= .1f;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */
/* Updated: 2025/06/03 15:18:22 by qmennen ### ########.fr */
/* Updated: 2025/06/04 18:42:13 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,3 +28,16 @@ int player_create(t_game **game)
(*game)->player = player;
return (SUCCESS);
}
void interact_door(t_game *game)
{
t_vec2_int pos;
pos = vec2_to_int(add(game->player->pos, game->player->dir));
printf("Tile to flash: (%d, %d), type %d\n", pos.x, pos.y, game->map->grid[pos.y][pos.x]);
if (game->map->grid[pos.y][pos.x] == TILE_DOOR)
{
game->map->grid[pos.y][pos.x] = TILE_EMPTY;
game->scoreboard->tiles_visited++;
}
}

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
/* Updated: 2025/06/03 16:16:56 by qmennen ### ########.fr */
/* Updated: 2025/06/04 17:57:29 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,10 +29,10 @@ mlx_texture_t *load_texture(const char *path)
t_token_handler handle_config_token(const char *token, t_map *map)
{
const char *config_tokens[] = {
"NO", "SO", "WE", "EA", "F", "C", "FT", "CT", "-c", "-s", "-e", NULL
"NO", "SO", "WE", "EA", "D", "F", "C", "FT", "CT", "-c", "-s", "-e", NULL
};
const t_token_handler handlers[] = {
handle_wall, handle_wall, handle_wall, handle_wall,
handle_wall, handle_wall, handle_wall, handle_wall, handle_wall,
handle_fc_color, handle_fc_color, handle_fc_texture, handle_fc_texture,
handle_sprite, handle_sprite, handle_sprite, NULL
};

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* parse_handlers.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/06/03 14:38:12 by whaffman #+# #+# */
/* Updated: 2025/06/03 14:54:00 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* parse_handlers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/03 14:38:12 by whaffman #+# #+# */
/* Updated: 2025/06/04 17:57:18 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,7 @@
int handle_wall(char *token, t_map *map)
{
const char *wall_tokens[] = {
"NO", "SO", "WE", "EA", NULL
"NO", "SO", "WE", "EA", "D", NULL
};
char *texture_path;
int i;

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* parse_tile.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/22 13:12:31 by whaffman #+# #+# */
/* Updated: 2025/05/25 11:49:44 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* parse_tile.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 13:12:31 by whaffman #+# #+# */
/* Updated: 2025/06/04 17:50:07 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,6 +22,8 @@ int parse_tile(char c)
return (TILE_VOID);
else if (c == 'N' || c == 'S' || c == 'E' || c == 'W')
return (TILE_PLAYER);
else if (c == 'D')
return (TILE_DOOR);
else if (c >= 'a' && c <= 'z')
return (TILE_EMPTY);
else

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* dda.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/02 11:58:09 by whaffman #+# #+# */
/* Updated: 2025/05/22 18:50:43 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* dda.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/02 11:58:09 by whaffman #+# #+# */
/* Updated: 2025/06/04 18:32:57 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -74,15 +74,18 @@ int dda_main(t_vec2 ray_dir, t_vec2_int map_pos, t_vec2 *side_dist, t_map *map)
printf("Out of bounds: %d %d\n", map_pos.x, map_pos.y);
if (map->grid[map_pos.y][map_pos.x] == TILE_EMPTY)
map->grid[map_pos.y][map_pos.x] = TILE_VISITED;
hit = (map->grid[map_pos.y][map_pos.x] == TILE_WALL);
hit = (map->grid[map_pos.y][map_pos.x] == TILE_WALL) - (map->grid[map_pos.y][map_pos.x] == TILE_DOOR);
}
side = -1 * (1 - side) + side;
if (hit == -1)
side *= 2;
return (side);
}
// Returns the distance to the wall hit if the wall is hit in y
// direction the result is negative, if the wall is hit
// in x direction the result is positive
double dda(t_vec2 ray_dir, t_vec2 pos, t_map *map)
double dda(t_render *render, t_vec2 ray_dir, t_vec2 pos, t_map *map)
{
const t_vec2 delta_dist = get_delta_dist(ray_dir);
t_vec2 side_dist;
@ -93,6 +96,12 @@ double dda(t_vec2 ray_dir, t_vec2 pos, t_map *map)
(t_vec2_int){(int)pos.x, (int)pos.y},
&side_dist,
map);
if (abs(side) == 2)
{
render->door = 1;
side /= 2;
}
side = (side + 1)/2;
return ((1 - side) * (side_dist.x - delta_dist.x)
- side * (side_dist.y - delta_dist.y));
}

View File

@ -1,19 +1,21 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* render_walls.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/14 13:05:28 by whaffman #+# #+# */
/* Updated: 2025/05/18 12:05:07 by whaffman ######## odam.nl */
/* ::: :::::::: */
/* render_walls.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/14 13:05:28 by whaffman #+# #+# */
/* Updated: 2025/06/04 18:17:33 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
t_side get_side(t_vec2 ray_dir, double perp_dist)
t_side get_side(t_render *render, t_vec2 ray_dir, double perp_dist)
{
if (render->door)
return (SIDE_DOOR);
if (perp_dist > 0)
{
if (ray_dir.x > 0)
@ -37,13 +39,14 @@ t_render cast_ray(t_game *game, int x)
t_render render;
double perp_dist;
render.door = 0;
ray_dir = add(game->player->dir,
mul(game->player->camera,
(2.0f * x / (double)game->screen->width - 1)));
pos = game->player->pos;
perp_dist = dda(ray_dir, pos, game->map);
perp_dist = dda(&render, ray_dir, pos, game->map);
render.perp_dist = fabs(perp_dist);
render.side = get_side(ray_dir, perp_dist);
render.side = get_side(&render, ray_dir, perp_dist);
if (perp_dist < 0)
render.wall_x = pos.x + ray_dir.x * render.perp_dist;
else

View File

@ -6,6 +6,7 @@ WE ./assets/bricks2.png
SO ./assets/stonewall256.png
EA ./assets/bricksx64.png
D ./assets/door.png
F 90,30,30
@ -20,7 +21,7 @@ CT ./assets/ceiling64x64.png
-s p ./assets/plant.png
-s m ./assets/broken_mirror.png
-s t ./assets/test.png
-e e ./assets/flying_eye.png
-s e ./assets/flying_eye.png
1111111 111 1111 111111 1111111111 111111
1000001110111001 100001 1000000001 10001
@ -30,7 +31,7 @@ CT ./assets/ceiling64x64.png
100m00111000100000b00000b00111110p00000100p00m001
10b0e0bb00001111111111100000000000111111000000001
1000t0bW00001 1000011111111 1000001001
10p0011111001 111111100001 1111111111110001
10p0011111DD1 111111100001 1111111111110001
100001 1001 1p00000000011111111000010111 10b01
111111 1001 10000010000000000010b0000101 100001
1b01 10000p1111111111111000010001 10b00m1