Merge branch 'willem_extra' into willem

This commit is contained in:
Quinten Mennen 2025-05-08 12:08:06 +02:00
commit 0a5355b13f
40 changed files with 354 additions and 332 deletions

BIN
assets/overlay.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

View File

@ -1,28 +1,28 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* collision.c :+: :+: :+: */ /* collision.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */ /* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
/* Updated: 2025/05/06 15:20:18 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:33:06 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "collision.h" #include "collision.h"
int collision_horizontal(t_map *map, t_player *player, double xa) int collision_horizontal(t_map *map, t_player *player, double xa)
{ {
t_tile tile; t_tile tile;
tile = get_tile(map, (int)((player->pos.x + xa)), (int)((player->pos.y))); 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);
} }
int collision_vertical(t_map *map, t_player *player, double ya) int collision_vertical(t_map *map, t_player *player, double ya)
{ {
t_tile tile; t_tile tile;
tile = get_tile(map, (int)((player->pos.x)), (int)((player->pos.y + ya))); 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);

View File

@ -12,7 +12,7 @@
#include "cub3d.h" #include "cub3d.h"
int game_create(t_game **game) int game_create(t_game **game)
{ {
*game = malloc(sizeof(t_game)); *game = malloc(sizeof(t_game));
if (!game) if (!game)
@ -24,7 +24,7 @@ int game_create(t_game **game)
return (SUCCESS); return (SUCCESS);
} }
void free_game(t_game **game) void free_game(t_game **game)
{ {
if (game && *game) if (game && *game)
{ {
@ -38,12 +38,12 @@ void free_game(t_game **game)
} }
} }
void game_loop(void *param) void game_loop(void *param)
{ {
t_game *game; t_game *game;
double delta_time; double delta_time;
static int framecount = 0; static int framecount = 0;
static int fps = 0; static int fps = 0;
framecount++; framecount++;
game = (t_game *)param; game = (t_game *)param;
@ -67,7 +67,7 @@ void game_loop(void *param)
} }
} }
void game_free(t_game *game) void game_free(t_game *game)
{ {
if (game->screen) if (game->screen)
{ {
@ -85,7 +85,7 @@ void game_free(t_game *game)
free(game); free(game);
} }
void game_terminate(t_game *game) void game_terminate(t_game *game)
{ {
game_free(game); game_free(game);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

View File

@ -6,13 +6,13 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/23 12:23:05 by whaffman #+# #+# */ /* Created: 2025/04/23 12:23:05 by whaffman #+# #+# */
/* Updated: 2025/04/23 12:23:14 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:51:33 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
t_tile get_tile(t_map *map, int x, int y) t_tile get_tile(t_map *map, int x, int y)
{ {
if (x < 0 || y < 0 || x >= map->width || y >= map->height) if (x < 0 || y < 0 || x >= map->width || y >= map->height)
return (TILE_WALL); return (TILE_WALL);

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/23 12:20:38 by whaffman #+# #+# */ /* Created: 2025/04/23 12:20:38 by whaffman #+# #+# */
/* Updated: 2025/04/23 12:21:00 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:21:14 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,11 @@ void grid_free(t_tile **grid, int height)
i = 0; i = 0;
while (i < height) while (i < height)
{ {
free(grid[i]); if (grid[i])
{
free(grid[i]);
grid[i] = NULL;
}
i++; i++;
} }
free(grid); free(grid);

View File

@ -1,18 +1,17 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* map_create.c :+: :+: :+: */ /* map_create.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@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/06 16:00:10 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:52:14 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
int map_create(t_game **game, const char *mapfile) int map_create(t_game **game, const char *mapfile)
{ {
t_tile **grid; t_tile **grid;
@ -26,7 +25,8 @@ int map_create(t_game **game, const char *mapfile)
return (FAILURE); return (FAILURE);
} }
ft_memset((*game)->map->textures, 0, sizeof((*game)->map->textures)); ft_memset((*game)->map->textures, 0, sizeof((*game)->map->textures));
parse_args(mapfile, (*game)); if (!parse_args(mapfile, (*game)))
return (FAILURE);
grid = copy_map((*game)->map->grid, (*game)->map->width, (*game)->map->height); grid = copy_map((*game)->map->grid, (*game)->map->width, (*game)->map->height);
if (!grid) if (!grid)
{ {
@ -44,6 +44,5 @@ int map_create(t_game **game, const char *mapfile)
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);
} }

View File

@ -6,17 +6,16 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/23 12:22:28 by whaffman #+# #+# */ /* Created: 2025/04/23 12:22:28 by whaffman #+# #+# */
/* Updated: 2025/04/23 12:22:49 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:51:46 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <stdlib.h> #include <stdlib.h>
#include "cub3d.h" #include "cub3d.h"
void map_free(t_map *map) void map_free(t_map *map)
{ {
grid_free(map->grid, map->height); grid_free(map->grid, map->height);
// free(map->grid);
free(map->NO_texture); free(map->NO_texture);
free(map->SO_texture); free(map->SO_texture);
free(map->WE_texture); free(map->WE_texture);

View File

@ -6,14 +6,13 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/25 09:54:24 by whaffman #+# #+# */ /* Created: 2025/04/25 09:54:24 by whaffman #+# #+# */
/* Updated: 2025/04/25 10:39:42 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:49:58 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
#include "math.h" #include "math.h"
t_vec2 add(t_vec2 a, t_vec2 b) t_vec2 add(t_vec2 a, t_vec2 b)
{ {
t_vec2 result; t_vec2 result;

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* dist.c :+: :+: :+: */ /* dist.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/25 10:07:59 by whaffman #+# #+# */ /* Created: 2025/04/25 10:07:59 by whaffman #+# #+# */
/* Updated: 2025/05/06 15:20:18 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:50:10 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
#include "math.h" #include "math.h"
#include "vec_math.h" #include "vec_math.h"
double dist(t_vec2 a, t_vec2 b) double dist(t_vec2 a, t_vec2 b)
{ {
return (sqrtf((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))); return (sqrtf((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)));
} }

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* dist_point_line.c :+: :+: :+: */ /* dist_point_line.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/25 10:09:45 by whaffman #+# #+# */ /* Created: 2025/04/25 10:09:45 by whaffman #+# #+# */
/* Updated: 2025/05/06 15:20:18 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:50:20 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,10 +14,10 @@
#include "math.h" #include "math.h"
#include "vec_math.h" #include "vec_math.h"
double dist_point_line(t_vec2 point, t_vec2_line line) double dist_point_line(t_vec2 point, t_vec2_line line)
{ {
double d; double d;
t_vec2 ps; t_vec2 ps;
ps = sub(line.support, point); ps = sub(line.support, point);
d = norm(sub(ps, mul(line.dir, dot(ps, line.dir)))); d = norm(sub(ps, mul(line.dir, dot(ps, line.dir))));

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* dot.c :+: :+: :+: */ /* dot.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/25 09:58:29 by whaffman #+# #+# */ /* Created: 2025/04/25 09:58:29 by whaffman #+# #+# */
/* Updated: 2025/05/06 15:20:18 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:50:27 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
#include "math.h" #include "math.h"
#include "vec_math.h" #include "vec_math.h"
double dot(t_vec2 a, t_vec2 b) double dot(t_vec2 a, t_vec2 b)
{ {
return (a.x * b.x + a.y * b.y); return (a.x * b.x + a.y * b.y);
} }

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* mul.c :+: :+: :+: */ /* mul.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/25 09:56:39 by whaffman #+# #+# */ /* Created: 2025/04/25 09:56:39 by whaffman #+# #+# */
/* Updated: 2025/05/06 15:20:18 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:50:43 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,9 +14,9 @@
#include "math.h" #include "math.h"
#include "vec_math.h" #include "vec_math.h"
t_vec2 mul(t_vec2 a, double b) t_vec2 mul(t_vec2 a, double b)
{ {
t_vec2 result; t_vec2 result;
result.x = a.x * b; result.x = a.x * b;
result.y = a.y * b; result.y = a.y * b;

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* norm.c :+: :+: :+: */ /* norm.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/25 09:59:13 by whaffman #+# #+# */ /* Created: 2025/04/25 09:59:13 by whaffman #+# #+# */
/* Updated: 2025/05/06 15:20:18 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:50:52 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
#include "math.h" #include "math.h"
#include "vec_math.h" #include "vec_math.h"
double norm(t_vec2 a) double norm(t_vec2 a)
{ {
return (sqrtf(a.x * a.x + a.y * a.y)); return (sqrtf(a.x * a.x + a.y * a.y));
} }

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/25 10:34:39 by whaffman #+# #+# */ /* Created: 2025/04/25 10:34:39 by whaffman #+# #+# */
/* Updated: 2025/04/25 10:40:17 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:50:59 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* rot.c :+: :+: :+: */ /* rot.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/25 10:35:58 by whaffman #+# #+# */ /* Created: 2025/04/25 10:35:58 by whaffman #+# #+# */
/* Updated: 2025/05/06 15:20:18 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:51:19 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,11 +14,11 @@
#include "math.h" #include "math.h"
#include "vec_math.h" #include "vec_math.h"
t_vec2 rot(t_vec2 a, double angle) t_vec2 rot(t_vec2 a, double angle)
{ {
t_vec2 result; t_vec2 result;
double cos_angle; double cos_angle;
double sin_angle; double sin_angle;
cos_angle = cosf(angle); cos_angle = cosf(angle);
sin_angle = sinf(angle); sin_angle = sinf(angle);

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/25 09:57:55 by whaffman #+# #+# */ /* Created: 2025/04/25 09:57:55 by whaffman #+# #+# */
/* Updated: 2025/04/25 10:40:27 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:51:07 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:02:31 by whaffman #+# #+# */ /* Created: 2025/04/22 13:02:31 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:03:03 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:47:41 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:04:07 by whaffman #+# #+# */ /* Created: 2025/04/22 13:04:07 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:06:41 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:47:48 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:08:26 by whaffman #+# #+# */ /* Created: 2025/04/22 13:08:26 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:08:37 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:48:11 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:13:07 by whaffman #+# #+# */ /* Created: 2025/04/22 13:13:07 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:19:40 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:48:00 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:08:52 by whaffman #+# #+# */ /* Created: 2025/04/22 13:08:52 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:09:33 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:47:55 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,7 +26,6 @@ unsigned int parse_color(const char *color_str)
|| !(tokens[2] && ft_strlen(tokens[2]) <= 3) || !(tokens[2] && ft_strlen(tokens[2]) <= 3)
|| tokens[3]) || tokens[3])
return (FAILURE); return (FAILURE);
r = ft_atoi(tokens[0]); r = ft_atoi(tokens[0]);
g = ft_atoi(tokens[1]); g = ft_atoi(tokens[1]);
b = ft_atoi(tokens[2]); b = ft_atoi(tokens[2]);

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */ /* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:10:23 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:48:16 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:11:37 by whaffman #+# #+# */ /* Created: 2025/04/22 13:11:37 by whaffman #+# #+# */
/* Updated: 2025/04/25 11:38:44 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:48:25 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,8 +14,8 @@
int parse_file(char *buffer, t_game *game) int parse_file(char *buffer, t_game *game)
{ {
char **lines; char **lines;
int i; int i;
lines = pointer_lines(buffer, '\n'); lines = pointer_lines(buffer, '\n');
if (!lines) if (!lines)

View File

@ -1,35 +1,39 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* 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/06 15:20:18 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:49:18 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
#include <math.h> #include <math.h>
t_vec2 parse_dir(int x, int y) t_vec2 parse_dir(int x, int y)
{ {
t_vec2 dir; t_vec2 dir;
dir.x = (double)x; dir.x = (double)x;
dir.y = (double)y; dir.y = (double)y;
return (dir); return (dir);
} }
int parse_player(t_game *game, int y, int x, char c) int parse_player(t_game *game, int y, int x, char c)
{ {
t_player *player; t_player *player;
player = game->player; player = game->player;
if (player->pos.x != -1 || player->pos.y != -1)
{
ft_putstr_fd("Error: Multiple players found\n", 2);
return (FAILURE);
}
player->pos.x = ((double)x + 0.5f); player->pos.x = ((double)x + 0.5f);
player->pos.y = ((double)y + 0.5f); player->pos.y = ((double)y + 0.5f);
if (c == 'N') if (c == 'N')
player->dir = parse_dir(0, -1); player->dir = parse_dir(0, -1);
else if (c == 'E') else if (c == 'E')
@ -38,15 +42,14 @@ int parse_player(t_game *game, int y, int x, char c)
player->dir = parse_dir(0, 1); player->dir = parse_dir(0, 1);
else if (c == 'W') else if (c == 'W')
player->dir = parse_dir(-1, 0); player->dir = parse_dir(-1, 0);
player->camera = rot(player->dir, 0.5f * M_PI); player->camera = rot(player->dir, 0.5f * M_PI);
return (SUCCESS); return (SUCCESS);
} }
int parse_map_line(char **lines, t_game *game, int y) int parse_map_line(char **lines, t_game *game, int y)
{ {
int x; int x;
t_map *map; t_map *map;
map = game->map; map = game->map;
map->grid[y] = malloc(sizeof(t_tile) * (map->width + 1)); map->grid[y] = malloc(sizeof(t_tile) * (map->width + 1));
@ -60,9 +63,10 @@ int parse_map_line(char **lines, t_game *game, int y)
else else
map->grid[y][x] = parse_tile(lines[y][x]); map->grid[y][x] = parse_tile(lines[y][x]);
if (map->grid[y][x] == TILE_PLAYER) if (map->grid[y][x] == TILE_PLAYER)
parse_player(game, y, x, lines[y][x]); {
else if (map->grid[y][x] == -2) if (!parse_player(game, y, x, lines[y][x]))
return (FAILURE); return (FAILURE);
}
if (map->grid[y][x] == -2) if (map->grid[y][x] == -2)
return (FAILURE); return (FAILURE);
x++; x++;
@ -70,10 +74,10 @@ int parse_map_line(char **lines, t_game *game, int y)
return (SUCCESS); return (SUCCESS);
} }
int parse_map(char **lines, t_game *game) int parse_map(char **lines, t_game *game)
{ {
int y; int y;
t_map *map; t_map *map;
y = 0; y = 0;
while (lines[y]) while (lines[y])
@ -84,13 +88,13 @@ int parse_map(char **lines, t_game *game)
map->grid = malloc(sizeof(t_tile *) * (map->height + 1)); map->grid = malloc(sizeof(t_tile *) * (map->height + 1));
if (!map->grid) if (!map->grid)
return (FAILURE); return (FAILURE);
ft_memset(map->grid, 0, sizeof(t_tile *) * (map->height + 1));
y = 0; y = 0;
while (y < map->height) while (y < map->height)
{ {
if (!parse_map_line(lines, game, y)) if (!parse_map_line(lines, game, y))
return (map_free(map), FAILURE); return (FAILURE);
y++; y++;
} }
map->grid[y] = NULL;
return (SUCCESS); return (SUCCESS);
} }

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:12:31 by whaffman #+# #+# */ /* Created: 2025/04/22 13:12:31 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:12:56 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:48:30 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,14 +6,14 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:03:24 by whaffman #+# #+# */ /* Created: 2025/04/22 13:03:24 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:17:28 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:48:40 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <stdlib.h> #include <stdlib.h>
#include "cub3d.h" #include "cub3d.h"
char **pointer_lines(char *buffer, char c) char **pointer_lines(char *buffer, char c)
{ {
char **lines; char **lines;
size_t count; size_t count;

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:11:18 by whaffman #+# #+# */ /* Created: 2025/04/22 13:11:18 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:11:28 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:49:07 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,6 +24,5 @@ void print_config(t_map *map)
printf("Floor color: %u\n", map->floor_color); printf("Floor color: %u\n", map->floor_color);
printf("Ceiling color: %u\n", map->ceiling_color); printf("Ceiling color: %u\n", map->ceiling_color);
printf("Grid:\n"); printf("Grid:\n");
print_map(map); print_map(map);
} }

View File

@ -6,11 +6,10 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/22 13:07:09 by whaffman #+# #+# */ /* Created: 2025/04/22 13:07:09 by whaffman #+# #+# */
/* Updated: 2025/04/22 13:07:56 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:49:04 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>

View File

@ -12,15 +12,15 @@
#include "cub3d.h" #include "cub3d.h"
int player_create(t_game **game) int player_create(t_game **game)
{ {
t_player *player; t_player *player;
player = malloc(sizeof(t_player)); player = malloc(sizeof(t_player));
if (!player) if (!player)
return (FAILURE); return (FAILURE);
player->pos.x = 1; player->pos.x = -1;
player->pos.y = 1; player->pos.y = -1;
player->dir.x = 1; player->dir.x = 1;
player->dir.y = 0; player->dir.y = 0;
player->camera.x = 0; player->camera.x = 0;
@ -32,10 +32,10 @@ int player_create(t_game **game)
return (SUCCESS); return (SUCCESS);
} }
static void move(t_map *map, t_player *player, int dir, double delta) static void move(t_map *map, t_player *player, int dir, double delta)
{ {
double xa; double xa;
double ya; double ya;
xa = dir * player->dir.x * player->speed * delta; xa = dir * player->dir.x * player->speed * delta;
ya = dir * player->dir.y * player->speed * delta; ya = dir * player->dir.y * player->speed * delta;
@ -51,10 +51,10 @@ static void move(t_map *map, t_player *player, int dir, double delta)
} }
} }
static void strave(t_map *map, t_player *player, int dir, double delta) static void strave(t_map *map, t_player *player, int dir, double delta)
{ {
double xa; double xa;
double ya; double ya;
xa = dir * perp(player->dir).x * player->speed * delta; xa = dir * perp(player->dir).x * player->speed * delta;
ya = dir * perp(player->dir).y * player->speed * delta; ya = dir * perp(player->dir).y * player->speed * delta;
@ -64,13 +64,13 @@ static void strave(t_map *map, t_player *player, int dir, double delta)
player->pos.y += ya; player->pos.y += ya;
} }
static void rotate(t_player *player, double rot_speed) static void rotate(t_player *player, double rot_speed)
{ {
player->dir = rot(player->dir, rot_speed); player->dir = rot(player->dir, rot_speed);
player->camera = rot(player->camera, rot_speed); player->camera = rot(player->camera, rot_speed);
} }
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;
if (get_key(game, MLX_KEY_W)) if (get_key(game, MLX_KEY_W))
@ -87,12 +87,13 @@ void player_update(t_game *game, double delta_time)
rotate(game->player, .05f); rotate(game->player, .05f);
} }
void player_render(t_screen *screen, t_player *player) void player_render(t_screen *screen, t_player *player)
{ {
t_vec2 direction; t_vec2 direction;
if (player->pos.x < 0 || player->pos.x >= screen->width || player->pos.y < 0 || player->pos.y >= screen->height) if (player->pos.x < 0 || player->pos.x >= screen->width
return; || player->pos.y < 0 || player->pos.y >= screen->height)
return ;
render_circle(screen, mul(player->pos, TILE_SIZE), 4, 0x111111ff); render_circle(screen, mul(player->pos, TILE_SIZE), 4, 0x111111ff);
direction = add(mul(player->pos, TILE_SIZE), mul(player->dir, TILE_SIZE)); direction = add(mul(player->pos, TILE_SIZE), mul(player->dir, TILE_SIZE));
render_line(screen, mul(player->pos, TILE_SIZE), direction, 0xa83232ff); render_line(screen, mul(player->pos, TILE_SIZE), direction, 0xa83232ff);

View File

@ -14,15 +14,14 @@
#include "vec_math.h" #include "vec_math.h"
#include <math.h> #include <math.h>
t_vec2 get_delta_dist(t_vec2 ray_dir) t_vec2 get_delta_dist(t_vec2 ray_dir)
{ {
t_vec2 delta_dist; t_vec2 delta_dist;
if (ray_dir.x == 0) if (ray_dir.x == 0)
delta_dist.x = 1e30; delta_dist.x = 1e30;
else else
delta_dist.x = fabs(1 / ray_dir.x); delta_dist.x = fabs(1 / ray_dir.x);
if (ray_dir.y == 0) if (ray_dir.y == 0)
delta_dist.y = 1e30; delta_dist.y = 1e30;
else else
@ -30,33 +29,35 @@ t_vec2 get_delta_dist(t_vec2 ray_dir)
return (delta_dist); return (delta_dist);
} }
t_vec2 get_step(t_vec2 ray_dir) t_vec2 get_step(t_vec2 ray_dir)
{ {
t_vec2 step; t_vec2 step;
step.x = 2 * (ray_dir.x >= 0) - 1; step.x = 2 * (ray_dir.x >= 0) - 1;
step.y = 2 * (ray_dir.y >= 0) - 1; step.y = 2 * (ray_dir.y >= 0) - 1;
return (step); return (step);
} }
t_vec2 get_side_dist(t_vec2 ray_dir, t_vec2 pos, t_vec2 delta_dist) t_vec2 get_side_dist(t_vec2 ray_dir, t_vec2 pos, t_vec2 delta_dist)
{ {
const t_vec2 frac_pos = (t_vec2){pos.x - (int)pos.x, pos.y - (int)pos.y}; const t_vec2 frac_pos = (t_vec2){pos.x - (int)pos.x, pos.y - (int)pos.y};
const int raydir_x_pos = (ray_dir.x >= 0); const int raydir_x_pos = (ray_dir.x >= 0);
const int raydir_y_pos = (ray_dir.y >= 0); const int raydir_y_pos = (ray_dir.y >= 0);
t_vec2 side_dist; t_vec2 side_dist;
side_dist.x = ((1 - raydir_x_pos) * frac_pos.x + raydir_x_pos * (1 - frac_pos.x)) * delta_dist.x; side_dist.x = ((1 - raydir_x_pos) * frac_pos.x
side_dist.y = ((1 - raydir_y_pos) * frac_pos.y + raydir_y_pos * (1 - frac_pos.y)) * delta_dist.y; + raydir_x_pos * (1 - frac_pos.x)) * delta_dist.x;
side_dist.y = ((1 - raydir_y_pos) * frac_pos.y
+ raydir_y_pos * (1 - frac_pos.y)) * delta_dist.y;
return (side_dist); return (side_dist);
} }
int dda_main(t_vec2 ray_dir, t_vec2_int map_pos, t_vec2 *side_dist, t_map *map) int dda_main(t_vec2 ray_dir, t_vec2_int map_pos, t_vec2 *side_dist, t_map *map)
{ {
const t_vec2 delta_dist = get_delta_dist(ray_dir); const t_vec2 delta_dist = get_delta_dist(ray_dir);
const t_vec2 step = get_step(ray_dir); const t_vec2 step = get_step(ray_dir);
int side; int side;
int hit; int hit;
hit = 0; hit = 0;
while (hit == 0) while (hit == 0)
@ -66,7 +67,10 @@ int dda_main(t_vec2 ray_dir, t_vec2_int map_pos, t_vec2 *side_dist, t_map *map)
side_dist->y += delta_dist.y * side; side_dist->y += delta_dist.y * side;
map_pos.x += step.x * (1 - side); map_pos.x += step.x * (1 - side);
map_pos.y += step.y * side; map_pos.y += step.y * side;
if (map_pos.x < 0 || map_pos.x >= map->width || map_pos.y < 0 || map_pos.y >= map->height) if (map_pos.x < 0
|| map_pos.x >= map->width
|| map_pos.y < 0
|| map_pos.y >= map->height)
printf("Out of bounds: %d %d\n", map_pos.x, map_pos.y); printf("Out of bounds: %d %d\n", map_pos.x, map_pos.y);
hit = (map->grid[map_pos.y][map_pos.x] == TILE_WALL); hit = (map->grid[map_pos.y][map_pos.x] == TILE_WALL);
} }
@ -76,21 +80,22 @@ int dda_main(t_vec2 ray_dir, t_vec2_int map_pos, t_vec2 *side_dist, t_map *map)
// Returns the distance to the wall hit if the wall is hit in y // Returns the distance to the wall hit if the wall is hit in y
// direction the result is negative, if the wall is hit // direction the result is negative, if the wall is hit
// in x direction the result is positive // in x direction the result is positive
double dda(t_vec2 ray_dir, t_vec2 pos, t_map *map) double dda(t_vec2 ray_dir, t_vec2 pos, t_map *map)
{ {
const t_vec2 delta_dist = get_delta_dist(ray_dir); const t_vec2 delta_dist = get_delta_dist(ray_dir);
t_vec2 side_dist; t_vec2 side_dist;
int side; int side;
side_dist = get_side_dist(ray_dir, pos, delta_dist); side_dist = get_side_dist(ray_dir, pos, delta_dist);
side = dda_main(ray_dir, side = dda_main(ray_dir,
(t_vec2_int){(int)pos.x, (int)pos.y}, (t_vec2_int){(int)pos.x, (int)pos.y},
&side_dist, &side_dist,
map); map);
return ((1 - side) * (side_dist.x - delta_dist.x) - side * (side_dist.y - delta_dist.y)); return ((1 - side) * (side_dist.x - delta_dist.x)
- side * (side_dist.y - delta_dist.y));
} }
t_side get_side(t_vec2 ray_dir, double perp_dist) t_side get_side(t_vec2 ray_dir, double perp_dist)
{ {
if (perp_dist > 0) if (perp_dist > 0)
{ {
@ -108,16 +113,16 @@ t_side get_side(t_vec2 ray_dir, double perp_dist)
} }
} }
t_render cast_ray(t_game *game, int x) t_render cast_ray(t_game *game, int x)
{ {
t_vec2 ray_dir; t_vec2 ray_dir;
t_vec2 pos; t_vec2 pos;
t_render render; t_render render;
double perp_dist; double perp_dist;
ray_dir = add(game->player->dir, ray_dir = add(game->player->dir,
mul(game->player->camera, mul(game->player->camera,
(2.0f * x / (double)game->screen->width - 1))); (2.0f * x / (double)game->screen->width - 1)));
pos = game->player->pos; pos = game->player->pos;
perp_dist = dda(ray_dir, pos, game->map); perp_dist = dda(ray_dir, pos, game->map);
render.perp_dist = fabs(perp_dist); render.perp_dist = fabs(perp_dist);
@ -130,77 +135,81 @@ t_render cast_ray(t_game *game, int x)
return (render); return (render);
} }
unsigned int get_texture_color(mlx_texture_t *texture, t_render render, int tex_x, int tex_y) unsigned int get_texture_color(mlx_texture_t *texture,
t_render render, int tex_x, int tex_y)
{ {
int index; int index;
double dist; double dist;
index = (tex_x + tex_y * texture->height) * texture->bytes_per_pixel; index = (tex_x + tex_y * texture->height) * texture->bytes_per_pixel;
dist = (render.perp_dist == 0) * 1e30 + (render.perp_dist > 1) * render.perp_dist + (render.perp_dist <= 1) * 1; dist = (render.perp_dist == 0) * 1e30
return texture->pixels[index] << 24 | texture->pixels[index + 1] << 16 | texture->pixels[index + 2] << 8 | (int)(1.0 / dist * 255); + (render.perp_dist > 1) * render.perp_dist
+ (render.perp_dist <= 1) * 1;
return (texture->pixels[index] << 24
| texture->pixels[index + 1] << 16
| texture->pixels[index + 2] << 8
| (int)(1.0 / dist * 255));
} }
void draw_line(t_game *game, t_render render, int x) void draw_line(t_game *game, t_render render, int x)
{ {
int y; int y;
int color; int color;
int lineHeight; int height;
int drawStart; int start;
int texDrawStart; int tex_start;
int drawEnd; int end;
int tex_x; int tex_x;
int tex_y; int tex_y;
lineHeight = (int)(game->screen->height / render.perp_dist); height = (int)(game->screen->height / render.perp_dist);
drawStart = -lineHeight / 2 + game->screen->height / 2; start = -height / 2 + game->screen->height / 2;
texDrawStart = drawStart; tex_start = start;
if (drawStart < 0) if (start < 0)
drawStart = 0; start = 0;
drawEnd = lineHeight / 2 + game->screen->height / 2; end = height / 2 + game->screen->height / 2;
if (drawEnd >= game->screen->height) if (end >= game->screen->height)
drawEnd = game->screen->height - 1; end = game->screen->height - 1;
tex_x = (int)(render.wall_x * (double)game->map->textures[render.side]->width); tex_x = (int)(render.wall_x * (double)game->map->textures[render.side]->width);
if (render.side == SIDE_NORTH || render.side == SIDE_EAST) if (render.side == SIDE_NORTH || render.side == SIDE_EAST)
tex_x = game->map->textures[render.side]->width - tex_x - 1; tex_x = game->map->textures[render.side]->width - tex_x - 1;
y = drawStart; y = start;
while (y < drawEnd) while (y < end)
{ {
tex_y = (int)(((double) game->map->textures[render.side]->height / (double) lineHeight) * (y - texDrawStart)); tex_y = (int)(((double) game->map->textures[render.side]->height / (double) height) * (y - tex_start));
color = get_texture_color(game->map->textures[render.side], render, tex_x, tex_y); color = get_texture_color(game->map->textures[render.side], render, tex_x, tex_y);
if (x < 0 || x >= game->screen->width || y < 0 || y >= game->screen->height) if (x < 0 || x >= game->screen->width || y < 0 || y >= game->screen->height)
break; break ;
mlx_put_pixel(game->screen->img, x, y, color); mlx_put_pixel(game->screen->img, x, y, color);
y++; y++;
} }
} }
void draw_floor(t_game *game) void draw_floor(t_game *game)
{ {
int y; int y;
int x; int x;
int color; int color;
double row_dist; double row_dist;
t_vec2 floor_step; t_vec2 floor_step;
t_vec2 floor_pos; t_vec2 floor_pos;
t_vec2_int floor_cell; t_vec2_int floor_cell;
t_vec2_int tex_coords; t_vec2_int tex_coords;
const t_vec2 left_ray = sub(game->player->dir, game->player->camera); const t_vec2 left_ray = sub(game->player->dir, game->player->camera);
const t_vec2 right_ray = add(game->player->dir, game->player->camera); const t_vec2 right_ray = add(game->player->dir, game->player->camera);
y = game->screen->height / 2; y = game->screen->height / 2;
while (y < game->screen->height ) while (y < game->screen->height)
{ {
row_dist = 0.5 * game->screen->height / (y - game->screen->height / 2.0); row_dist = 0.5 * game->screen->height / (y - game->screen->height / 2.0);
floor_step = mul(mul(sub(right_ray, left_ray), row_dist), 1.0 / game->screen->width); floor_step = mul(mul(sub(right_ray, left_ray), row_dist), 1.0 / game->screen->width);
floor_pos = add(game->player->pos, mul(left_ray, row_dist)); floor_pos = add(game->player->pos, mul(left_ray, row_dist));
x = 0; x = 0;
while (x < game->screen->width) while (x < game->screen->width)
{ {
floor_cell = (t_vec2_int){(int)floor_pos.x, (int)floor_pos.y}; floor_cell = (t_vec2_int){(int)floor_pos.x, (int)floor_pos.y};
tex_coords = (t_vec2_int){(int) (64 * (floor_pos.x - floor_cell.x)) & 63, tex_coords = (t_vec2_int){(int)(64 * (floor_pos.x - floor_cell.x)) & 63,
(int) (64 * (floor_pos.y - floor_cell.y)) & 63}; (int)(64 * (floor_pos.y - floor_cell.y)) & 63};
floor_pos = add(floor_pos, floor_step); floor_pos = add(floor_pos, floor_step);
color = get_texture_color(game->map->texture_floor, (t_render){row_dist, 0, 0}, tex_coords.x, tex_coords.y); color = get_texture_color(game->map->texture_floor, (t_render){row_dist, 0, 0}, tex_coords.x, tex_coords.y);
mlx_put_pixel(game->screen->img, x, y, color); mlx_put_pixel(game->screen->img, x, y, color);
@ -212,7 +221,7 @@ void draw_floor(t_game *game)
} }
} }
void cast_rays(t_game *game) void cast_rays(t_game *game)
{ {
int x; int x;
t_render render; t_render render;
@ -226,4 +235,3 @@ void cast_rays(t_game *game)
x++; x++;
} }
} }

View File

@ -1,64 +1,67 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* render.c :+: :+: :+: */ /* render.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@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/06 19:02:53 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:38:34 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "render.h" #include "render.h"
#include "MLX42.h" #include "MLX42.h"
int render_check_bounds(t_screen *screen, t_vec2 *point) 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); 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) void render_tile(t_screen *screen, int x, int y, t_tile tile)
{ {
int i; int i;
int xp; int xp;
int yp; int yp;
i = 0; i = 0;
if (tile < 0) if (tile < 0)
return; return ;
while ((i++) < TILE_SIZE * TILE_SIZE) while ((i++) < TILE_SIZE * TILE_SIZE)
{ {
xp = x + (i % TILE_SIZE); xp = x + (i % TILE_SIZE);
yp = y + (i / TILE_SIZE); yp = y + (i / TILE_SIZE);
if (xp < 0 || xp >= screen->width || yp < 0 || yp >= screen->height) if (xp < 0 || xp >= screen->width || yp < 0 || yp >= screen->height)
continue; continue ;
if (tile == TILE_WALL) if (tile == TILE_WALL)
mlx_put_pixel(screen->minimap, xp, yp, 0xA88132aa); mlx_put_pixel(screen->minimap, xp, yp, 0xA88132aa);
else if (tile == TILE_EMPTY || tile == TILE_PLAYER) else if (tile == TILE_EMPTY || tile == TILE_PLAYER)
mlx_put_pixel(screen->minimap, xp, yp, 0xaaaaaa44); mlx_put_pixel(screen->minimap, xp, yp, 0xaaaaaa44);
} }
} }
void render_map(t_screen *screen, t_map *map) void render_map(t_screen *screen, t_map *map)
{ {
int i; int i;
int x; int x;
int y; int y;
i = 0; i = 0;
while (i < map->width * map->height) while (i < map->width * map->height)
{ {
x = i % map->width; x = i % map->width;
y = i / map->width; y = i / map->width;
if (x < 0 || x >= map->width || y < 0 || y >= map->height) if (x < 0 || x >= map->width || y < 0 || y >= map->height)
continue; continue ;
render_tile(screen, x * TILE_SIZE, y * TILE_SIZE, map->grid[y][x]); render_tile(screen, x * TILE_SIZE, y * TILE_SIZE, map->grid[y][x]);
i++; i++;
} }
} }
void render_entities(t_game *game) void render_entities(t_game *game)
{ {
player_render(game->screen, game->player); player_render(game->screen, game->player);
} }

View File

@ -6,13 +6,14 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/17 20:06:19 by qmennen #+# #+# */ /* Created: 2025/04/17 20:06:19 by qmennen #+# #+# */
/* Updated: 2025/05/04 16:55:14 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:37:29 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "render.h" #include "render.h"
void render_circle(t_screen *screen, t_vec2 point, int radius, unsigned int color) void render_circle(t_screen *screen,
t_vec2 point, int radius, unsigned int color)
{ {
int i; int i;
int size; int size;
@ -26,7 +27,8 @@ void render_circle(t_screen *screen, t_vec2 point, int radius, unsigned int colo
x = i % size - radius; x = i % size - radius;
y = i / size - radius; y = i / size - radius;
if (x * x + y * y <= radius * radius) if (x * x + y * y <= radius * radius)
mlx_put_pixel(screen->minimap, (int) point.x + x, (int) point.y + y, color); mlx_put_pixel(screen->minimap,
(int) point.x + x, (int) point.y + y, color);
i++; i++;
} }
} }

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/17 20:05:51 by qmennen #+# #+# */ /* Created: 2025/04/17 20:05:51 by qmennen #+# #+# */
/* Updated: 2025/05/04 16:55:44 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:37:36 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,6 +18,6 @@ void render_clear(t_screen *screen)
i = 0; i = 0;
while (i++ < screen->width * screen->height) while (i++ < screen->width * screen->height)
mlx_put_pixel(screen->minimap, i % screen->width, i / screen->width, 0x0); mlx_put_pixel(screen->minimap,
i % screen->width, i / screen->width, 0x0);
} }

View File

@ -6,17 +6,18 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/17 20:06:40 by qmennen #+# #+# */ /* Created: 2025/04/17 20:06:40 by qmennen #+# #+# */
/* Updated: 2025/05/04 16:56:16 by whaffman ######## odam.nl */ /* Updated: 2025/05/07 11:36:57 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "render.h" #include "render.h"
static void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) static void line_low(t_screen *screen,
t_vec2 start, t_vec2 end, unsigned int color)
{ {
int delta; int delta;
int yi; int yi;
t_vec2 current; t_vec2 cur;
t_vec2 delta_point; t_vec2 delta_point;
delta_point.x = end.x - start.x; delta_point.x = end.x - start.x;
@ -25,27 +26,28 @@ static void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int co
if (end.y - start.y < 0) if (end.y - start.y < 0)
yi = -1; yi = -1;
delta = 2 * delta_point.y - delta_point.x; delta = 2 * delta_point.y - delta_point.x;
current = start; cur = start;
while (current.x <= end.x) while (cur.x <= end.x)
{ {
if (render_check_bounds(screen, &current)) if (render_check_bounds(screen, &cur))
mlx_put_pixel(screen->minimap, (int)current.x, (int)current.y, color); mlx_put_pixel(screen->minimap, (int)cur.x, (int)cur.y, color);
if (delta > 0) if (delta > 0)
{ {
current.y += yi; cur.y += yi;
delta -= 2 * delta_point.x; delta -= 2 * delta_point.x;
} }
delta += 2 * delta_point.y; delta += 2 * delta_point.y;
current.x++; cur.x++;
} }
} }
static void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) static void line_high(t_screen *screen,
t_vec2 start, t_vec2 end, unsigned int color)
{ {
int delta; int delta;
int xi; int xi;
t_vec2 current; t_vec2 cur;
t_vec2 delta_point; t_vec2 delta_point;
delta_point.x = abs((int) end.x - (int) start.x); delta_point.x = abs((int) end.x - (int) start.x);
delta_point.y = end.y - start.y; delta_point.y = end.y - start.y;
@ -53,22 +55,23 @@ static void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int c
if (end.x - start.x < 0) if (end.x - start.x < 0)
xi = -1; xi = -1;
delta = 2 * delta_point.x - delta_point.y; delta = 2 * delta_point.x - delta_point.y;
current = start; cur = start;
while (current.y <= end.y) while (cur.y <= end.y)
{ {
if (render_check_bounds(screen, &current)) if (render_check_bounds(screen, &cur))
mlx_put_pixel(screen->minimap, (int)current.x, (int)current.y, color); mlx_put_pixel(screen->minimap, (int)cur.x, (int)cur.y, color);
if (delta > 0) if (delta > 0)
{ {
current.x += xi; cur.x += xi;
delta -= 2 * delta_point.y; delta -= 2 * delta_point.y;
} }
delta += 2 * delta_point.x; delta += 2 * delta_point.x;
current.y++; cur.y++;
} }
} }
void render_line(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) 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 if ((start.x < 0 || start.x >= (int) screen->img->width
|| start.y < 0 || start.y >= (int) screen->img->height) || start.y < 0 || start.y >= (int) screen->img->height)

View File

@ -63,6 +63,8 @@ int screen_display(t_screen *screen)
int m_width; int m_width;
int m_height; int m_height;
m_width = 0; m_width = 0;
m_height = 0; m_height = 0;
fill_background(screen, 0x000000FF); fill_background(screen, 0x000000FF);

View File

@ -1,20 +1,20 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* texutre_load.c :+: :+: :+: */ /* texutre_load.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/05/06 15:45:58 by qmennen #+# #+# */ /* Created: 2025/05/06 15:45:58 by qmennen #+# #+# */
/* Updated: 2025/05/06 19:01:15 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:49:37 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "texture.h" #include "texture.h"
void texture_delete(t_game *game) void texture_delete(t_game *game)
{ {
int i; int i;
i = 0; i = 0;
while (i < 4) while (i < 4)
@ -35,7 +35,7 @@ void texture_delete(t_game *game)
} }
} }
int texture_load(t_game *game) int texture_load(t_game *game)
{ {
game->map->textures[SIDE_NORTH] = mlx_load_png(game->map->NO_texture); game->map->textures[SIDE_NORTH] = mlx_load_png(game->map->NO_texture);
game->map->textures[SIDE_EAST] = mlx_load_png(game->map->EA_texture); game->map->textures[SIDE_EAST] = mlx_load_png(game->map->EA_texture);

View File

@ -1,19 +1,19 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* errors.c :+: :+: :+: */ /* errors.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/15 15:40:14 by qmennen #+# #+# */ /* Created: 2025/04/15 15:40:14 by qmennen #+# #+# */
/* Updated: 2025/04/15 16:10:57 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:34:57 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "MLX42.h" #include "MLX42.h"
#include "cub3d.h" #include "cub3d.h"
const char *last_error() const char *last_error(void)
{ {
if (mlx_errno > 0) if (mlx_errno > 0)
return (mlx_strerror(mlx_errno)); return (mlx_strerror(mlx_errno));
@ -26,6 +26,7 @@ const char *last_error()
void game_error(t_game *game, const char *msg) void game_error(t_game *game, const char *msg)
{ {
const char *last_err = last_error(); const char *last_err = last_error();
if (msg == NULL && last_err) if (msg == NULL && last_err)
printf(RED"%s\n"RESET, last_err); printf(RED"%s\n"RESET, last_err);
else else

View File

@ -1,18 +1,18 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* initialize.c :+: :+: :+: */ /* initialize.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@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/06 16:18:44 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:35:18 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
int initialize_cub3d(t_game **game, const char *mapfile) int initialize_cub3d(t_game **game, const char *mapfile)
{ {
if (!game_create(game)) if (!game_create(game))
return (FAILURE); return (FAILURE);

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* keyboard.c :+: :+: :+: */ /* keyboard.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/17 19:29:29 by qmennen #+# #+# */ /* Created: 2025/04/17 19:29:29 by qmennen #+# #+# */
/* Updated: 2025/04/22 14:46:18 by qmennen ### ########.fr */ /* Updated: 2025/05/07 11:35:41 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -44,7 +44,7 @@ void keyboard_update(t_game *game)
int get_key(t_game *game, int k) int get_key(t_game *game, int k)
{ {
return mlx_is_key_down(game->screen->mlx, k); return (mlx_is_key_down(game->screen->mlx, k));
} }
int get_key_down(t_game *game, int k) int get_key_down(t_game *game, int k)

View File

@ -19,7 +19,7 @@ C 100,100,200
1000001110000001110011111111 110000001000000001 1000001110000001110011111111 110000001000000001
1000001 10001000000010000001 100000001000000001 1000001 10001000000010000001 100000001000000001
1000001110001000000000000001111100000001000000001 1000001110001000000000000001111100000001000000001
100W000000001111111111100000000000111111000000001 1000000000001111111111100000000000111111000000001
1000000W00001 1000011111111 1000001001 1000000W00001 1000011111111 1000001001
1000011111001 111111100001 1111111111110001 1000011111001 111111100001 1111111111110001
100001 1001 1000000000011111111000010111 10001 100001 1001 1000000000011111111000010111 10001