-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into sprites
- Loading branch information
Showing
36 changed files
with
385 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"files.associations": { | ||
"cstdlib": "c", | ||
"stdio.h": "c" | ||
} | ||
"cstdlib": "c", | ||
"stdio.h": "c", | ||
"meta.h": "c" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: W2Wizard <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2021/12/27 23:55:34 by W2Wizard #+# #+# */ | ||
/* Updated: 2024/01/17 12:49:14 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/01/20 00:49:21 by joppe ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jboeve <[email protected]>+#+ */ | ||
/* +#+ */ | ||
/* Created: 2023/11/01 20:07:37 by jboeve#+##+# */ | ||
/* Updated: 2024/01/18 11:56:06 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/01/20 01:14:53 by joppe ######## odam.nl */ | ||
/**/ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -23,6 +23,7 @@ | |
#include <fcntl.h> | ||
#include <stdbool.h> | ||
#include <limits.h> | ||
#include <math.h> | ||
|
||
#include "timer.h" | ||
#include "libft.h" | ||
|
@@ -56,16 +57,16 @@ | |
#define WINDOW_WIDTH 1280 | ||
#define WINDOW_HEIGHT 720 | ||
|
||
#define BPP 4 | ||
|
||
|
||
// Game | ||
#define TICK_RATE (1.0 / 60.0) | ||
|
||
#define PLAYER_MOVE_SPEED 5.0 | ||
#define PLAYER_MOVE_SPEED 3.5 | ||
#define PLAYER_RUN_MODIFIER 2.5 | ||
#define PLAYER_ROTATE_SPEED 5.0 | ||
#define PLAYER_ROTATE_SPEED 3.0 | ||
#define PLAYER_ROTATE_MODIFIER 2.5 | ||
#define PLAYER_MOV_SPEED 0.08 | ||
|
||
#define MINIMAP_WIDTH 350 | ||
#define MINIMAP_HEIGHT 230 | ||
|
@@ -81,7 +82,6 @@ | |
#define VIEWPORT_COLOR_WALL_NS 0x4B0082FF | ||
#define VIEWPORT_COLOR_WALL_EW 0x8A30E2FF | ||
|
||
// #define FOV 0.66 | ||
#define FOV 0.85 | ||
|
||
typedef bool (t_ray_hitfunc) (const void *p, uint32_t x, uint32_t y); | ||
|
@@ -92,6 +92,7 @@ typedef enum e_cell_type { | |
MAP_EMPTY, | ||
MAP_WALL, | ||
MAP_SPACE, | ||
MAP_DOOR | ||
} t_cell_type; | ||
|
||
typedef enum e_font_family { | ||
|
@@ -126,10 +127,10 @@ typedef union s_rgba | |
|
||
|
||
typedef enum e_side { | ||
SIDE_N, | ||
SIDE_S, | ||
SIDE_E, | ||
SIDE_W, | ||
SIDE_N = 0, | ||
SIDE_S = 1, | ||
SIDE_E = 2, | ||
SIDE_W = 3, | ||
} t_side; | ||
|
||
typedef struct s_ray { | ||
|
@@ -147,9 +148,16 @@ typedef struct s_ray { | |
double step; | ||
} t_ray; | ||
|
||
typedef struct s_vray { | ||
t_vec2d floor; | ||
t_vec2d step; | ||
} t_vray; | ||
|
||
typedef struct s_player { | ||
t_meta *meta; | ||
t_ray rays[WINDOW_WIDTH]; | ||
t_vray vrays[WINDOW_HEIGHT]; | ||
bool should_render; | ||
t_vec2d cam_plane; | ||
t_vec2d position; | ||
t_vec2d direction; | ||
|
@@ -171,10 +179,13 @@ typedef struct s_tex { | |
} t_tex; | ||
|
||
typedef struct s_attr { | ||
t_tex n; | ||
t_tex n; //add bit flag, if tex_path is missing then it means it is a color value | ||
t_tex s; | ||
t_tex e; | ||
t_tex w; | ||
t_tex f; | ||
t_tex c; | ||
t_tex c_alt; | ||
t_rgba floor_c; | ||
t_rgba ceiling_c; | ||
} t_attr; | ||
|
@@ -258,4 +269,7 @@ int set_textures(t_attr *attributes); | |
uint32_t pixel_picker(mlx_texture_t *texture, int32_t x, int32_t y); | ||
void wall_texture_position(mlx_texture_t *texture, t_ray *ray, t_vec2i line_points, uint32_t h); | ||
|
||
// floorcaster.c | ||
t_vray floorcaster(t_vec2d pp, t_vec2d dir, t_vec2d cam_plane, uint32_t y); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
/* ************************************************************************** */ | ||
/**/ | ||
/* :::::::: */ | ||
/* test_utils.h :+::+: */ | ||
/*+:+ */ | ||
/* By: joppe <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/02 19:56:05 by joppe #+##+# */ | ||
/* Updated: 2024/01/02 23:20:17 by joppe ######## odam.nl */ | ||
/**/ | ||
/* */ | ||
/* :::::::: */ | ||
/* test_utils.h :+: :+: */ | ||
/* +:+ */ | ||
/* By: jboeve <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/18 13:59:19 by jboeve #+# #+# */ | ||
/* Updated: 2024/01/18 14:10:07 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
||
|
@@ -23,5 +23,5 @@ void print_cell(t_cell_type cell); | |
void print_map(char *map, uint32_t w, uint32_t h); | ||
void print_map_cell(t_cell_type *level, uint32_t w, uint32_t h); | ||
void print_ray(const char *s, const t_ray *r); | ||
|
||
void print_direction(t_side dir); | ||
#endif // !TEST_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/**/ | ||
/* :::::::: */ | ||
/* vector.h :+::+: */ | ||
/* vector.h :+: :+: */ | ||
/*+:+ */ | ||
/* By: joppe <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/02 19:07:15 by joppe #+##+# */ | ||
/* Updated: 2024/01/03 18:35:23 by joppe ######## odam.nl */ | ||
/* Updated: 2024/01/19 23:36:47 by joppe ######## odam.nl */ | ||
/**/ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -35,6 +35,7 @@ typedef struct s_vec2u { | |
t_vec2d vec2d_add(t_vec2d v1, t_vec2d v2); | ||
t_vec2d vec2d_sub(t_vec2d v1, t_vec2d v2); | ||
t_vec2d vec2d_scalar_product(t_vec2d vec, double scalar); | ||
double vec2d_dot_product(t_vec2d v1, t_vec2d v2); | ||
t_vec2d vec2d_mul(t_vec2d v1, t_vec2d v2); | ||
t_vec2d vec2d_rotate(t_vec2d old, double radiant); | ||
t_vec2d vec2d_normalize(t_vec2d vec); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* cub3d.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:24:47 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/18 10:45:29 by jboeve ######## odam.nl */ | ||
/* :::::::: */ | ||
/* cub3d.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/08 15:24:47 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 11:14:56 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "MLX42/MLX42.h" | ||
#include "MLX42/MLX42_Int.h" | ||
// #include "MLX42/MLX42_Int.h" | ||
#include "meta.h" | ||
#include "parser.h" | ||
#include <stdint.h> | ||
|
@@ -111,6 +111,8 @@ int cub3d(int argc, char **argv) | |
printf("Tex_S: %s\n", meta.attributes.s.tex_path); | ||
printf("Tex_E: %s\n", meta.attributes.e.tex_path); | ||
printf("Tex_W: %s\n", meta.attributes.w.tex_path); | ||
printf("Tex_C: %s\n", meta.attributes.c.tex_path); | ||
printf("Tex_F: %s\n", meta.attributes.f.tex_path); | ||
|
||
init_mlx_images(&meta); | ||
// TODO Error check. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* :::::::: */ | ||
/* floorcaster.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/24 13:13:37 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 18:23:45 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "meta.h" | ||
|
||
t_vray floorcaster(t_vec2d pp, t_vec2d dir, t_vec2d cam_plane, uint32_t y) | ||
{ | ||
t_vray ray; | ||
t_vec2d raydir_left; | ||
t_vec2d raydir_right; | ||
|
||
raydir_left = ((t_vec2d){dir.x - cam_plane.x, dir.y - cam_plane.y}); | ||
raydir_right = ((t_vec2d){dir.x + cam_plane.x, dir.y + cam_plane.y}); | ||
|
||
int p = y - WINDOW_HEIGHT / 2; | ||
double posZ = 0.5 * WINDOW_HEIGHT; | ||
double row_distance = posZ / p; | ||
ray.step.x = row_distance * (raydir_right.x - raydir_left.x) / WINDOW_WIDTH; | ||
ray.step.y = row_distance * (raydir_right.y - raydir_left.y) / WINDOW_WIDTH; | ||
|
||
ray.floor.x = pp.x + row_distance * raydir_left.x; | ||
ray.floor.y = pp.y + row_distance * raydir_left.y; | ||
|
||
return (ray); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,17 @@ | |
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:26:51 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/17 13:04:46 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/01/25 13:22:31 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "MLX42/MLX42.h" | ||
#include "meta.h" | ||
#include "timer.h" | ||
#include "vector.h" | ||
#include <assert.h> | ||
#include <math.h> | ||
#include <stdint.h> | ||
#include <unistd.h> | ||
#include "test_utils.h" | ||
|
||
|
@@ -54,6 +56,24 @@ void set_player_start_position(t_player *p, char dir) | |
p->position.y += 0.5; | ||
} | ||
|
||
|
||
|
||
|
||
void swap_tex(mlx_texture_t *tex) | ||
{ | ||
assert(tex->width == tex->height); | ||
|
||
for (size_t x = 0; x < tex->width; x++) | ||
{ | ||
for (size_t y = 0; y < x; y++) | ||
{ | ||
uint32_t pixel = tex->pixels[(tex->width * y + x) * BPP]; | ||
tex->pixels[(tex->width * y + x) * BPP] = tex->pixels[(tex->width * x + y) * BPP]; | ||
tex->pixels[(tex->width * x + y) * BPP] = pixel; | ||
} | ||
} | ||
} | ||
|
||
void game_init(t_meta *meta) | ||
{ | ||
t_player* const p = &meta->player; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* keys.c :+: :+: :+: */ | ||
/* keys.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:27:07 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:27:11 by yzaim ### ########.fr */ | ||
/* Updated: 2024/01/18 12:50:58 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -49,7 +49,6 @@ static void keys_handle_move(t_meta *meta, double delta_time) | |
pressed = true; | ||
trans = vec2d_add(trans, (t_vec2d) {(vec2d_rotate(p->direction, PI / 2).x) * speed, (vec2d_rotate(p->direction, PI / 2).y) * speed}); | ||
} | ||
|
||
if (pressed) | ||
player_move(p, trans); | ||
} | ||
|
Oops, something went wrong.