-
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 floor-ceiling-textures
- Loading branch information
Showing
15 changed files
with
130 additions
and
59 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 |
---|---|---|
|
@@ -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/25 12:34:26 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/01/20 01:14:53 by joppe ######## odam.nl */ | ||
/**/ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -57,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 | ||
|
@@ -127,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 { | ||
|
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
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); | ||
} | ||
|
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 |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
/* */ | ||
/* :::::::: */ | ||
/* player.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/08 15:27:23 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/25 12:49:14 by jboeve ######## odam.nl */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:27:23 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/25 13:21:42 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -21,7 +21,7 @@ | |
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
bool bound_check(void *param, uint32_t x, uint32_t y) | ||
bool bound_check(const void *param, uint32_t x, uint32_t y) | ||
{ | ||
t_meta *const meta = (t_meta *) param; | ||
if (x < meta->map.width && y < meta->map.height) | ||
|
@@ -32,21 +32,51 @@ bool bound_check(void *param, uint32_t x, uint32_t y) | |
} | ||
} | ||
|
||
void player_move(t_player *p, t_vec2d transform) | ||
void print_angle(t_player *p) | ||
{ | ||
t_vec2d new_position; | ||
|
||
new_position.x = (p->position.x + (transform.x)); | ||
new_position.y = (p->position.y + (transform.y)); | ||
// NORTH = 0 | ||
const float angle = (atan2(p->direction.x, p->direction.y) / PI * 180 + 180); | ||
if (angle > 45.0 && angle < 135.0) | ||
{ | ||
printf("N\n"); | ||
} | ||
else if (angle > 135.0 && angle < 225.0) | ||
{ | ||
printf("E\n"); | ||
} | ||
else if (angle > 225.0 && angle < 315.0) | ||
{ | ||
printf("S\n"); | ||
} | ||
else if (angle > 315.0 || angle < 45.0) | ||
{ | ||
printf("W\n"); | ||
} | ||
} | ||
|
||
// TODO Fix. | ||
void player_move(t_player *p, t_vec2d transform) | ||
{ | ||
t_ray r = raycaster_cast(p->position, vec2d_normalize(transform), bound_check, p->meta); | ||
// print_ray("bound_ray", &r); | ||
|
||
if (r.length > .5) | ||
if (r.length > 0.4) | ||
p->position = vec2d_add(p->position, transform); | ||
else | ||
{ | ||
p->position.x += transform.x; | ||
p->position.y += transform.y; | ||
const int comp = (r.hit_side == SIDE_N || r.hit_side == SIDE_S); | ||
const t_vec2d normal = {comp, !comp}; // 1, 0 // 0, 1 | ||
const double dot_product = vec2d_dot_product(transform, normal); | ||
|
||
|
||
t_vec2d delta_pos; | ||
delta_pos.x = transform.x - normal.x * dot_product; | ||
delta_pos.y = transform.y - normal.y * dot_product; | ||
r = raycaster_cast(p->position, vec2d_normalize(transform), bound_check, p->meta); | ||
|
||
if (r.length > 0.35) | ||
{ | ||
p->position.x += delta_pos.x; | ||
p->position.y += delta_pos.y; | ||
} | ||
} | ||
player_raycast(p); | ||
} | ||
|
@@ -68,6 +98,7 @@ void player_raycast(t_player *p) | |
t_vec2d ray_start; | ||
double camera_x; | ||
|
||
|
||
row = 0; | ||
while (row < h) | ||
{ | ||
|
@@ -78,9 +109,9 @@ void player_raycast(t_player *p) | |
|
||
// TODO Just create the player.plane here instead of saving it. | ||
col = 0; | ||
while(col < w) | ||
while (col < p->meta->image->width) | ||
{ | ||
camera_x = (2 * col / ((double) w) - 1); | ||
camera_x = (2 * col / ((double) p->meta->image->width) - 1); | ||
ray_start = vec2d_add(p->direction, vec2d_scalar_product(p->cam_plane, camera_x)); | ||
p->rays[col] = raycaster_cast(p->position, ray_start, bound_check, p->meta); | ||
// printf("wall x: %f\n", p->rays[col].wall_x); | ||
|
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,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* render_minimap.c :+: :+: :+: */ | ||
/* render_minimap.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:27:53 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:27:58 by yzaim ### ########.fr */ | ||
/* Updated: 2024/01/18 12:43:48 by jboeve ######## 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/08 15:28:08 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/25 00:35:46 by joppe ######## odam.nl */ | ||
/* Updated: 2024/01/20 01:18:16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* test_utils.c :+: :+: :+: */ | ||
/* test_utils.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:25:38 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:25:49 by yzaim ### ########.fr */ | ||
/* Updated: 2024/01/18 14:10:17 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -31,6 +31,18 @@ void print_ray(const char *s, const t_ray *r) | |
printf("[%s] | ray_direction [%lf][%lf] | length [%lf] | ray_end [%lf][%lf] | hit_side [%s]\n", s, r->direction.x, r->direction.y, r->length, r->end.x, r->end.y, side_text); | ||
} | ||
|
||
void print_direction(t_side dir) | ||
{ | ||
const char *text[4] = { | ||
[SIDE_N] = "N", | ||
[SIDE_E] = "E", | ||
[SIDE_S] = "S", | ||
[SIDE_W] = "W", | ||
}; | ||
|
||
printf("[%s]\n", text[dir]); | ||
} | ||
|
||
void print_cell(t_cell_type cell) | ||
{ | ||
printf("cell [%s]\n", CELL_NAMES[cell]); | ||
|
Oops, something went wrong.