Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doors #27

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
99e0d22
have not finished adding doors
Feb 7, 2024
18f2d40
applying doors
Feb 7, 2024
cf9d21c
adding doors
Feb 7, 2024
b9f60d6
compiles now
Feb 8, 2024
2a948cf
parser for doors kinda working
Feb 8, 2024
22ae619
Merge branch 'parser_with_sprites' into doors
ys-zm Feb 9, 2024
b5c7ad8
added door tex
ys-zm Feb 9, 2024
925bf62
Add MAP_DOOR_OPEN MAP_DOOR_CLOSED
JopjeKnopje Feb 9, 2024
06604ae
changed door t_cell
ys-zm Feb 9, 2024
bdb7395
Wonky kinda works
JopjeKnopje Feb 9, 2024
f3a94b1
Can kinda toggle doors
JopjeKnopje Feb 9, 2024
31c90dc
Fix keys issue
JopjeKnopje Feb 9, 2024
6c434a3
Change y to x which fixed the doors randomly spawning
JopjeKnopje Feb 9, 2024
fc49e47
Can open doors without rotating first.
JopjeKnopje Feb 9, 2024
11a4f3d
fix workflow
JopjeKnopje Feb 9, 2024
572af27
Can kinda move a wall, only issue is the side texture of the nearby
JopjeKnopje Feb 9, 2024
6389030
cleaned up parser and added next level path
ys-zm Feb 10, 2024
8e0bcd8
can draw line where the texture should "fold"
JopjeKnopje Feb 10, 2024
ca521e0
Bla bla
JopjeKnopje Feb 10, 2024
7c43f95
Kinda buggy
JopjeKnopje Feb 11, 2024
ffb89ad
Fix raycaster directions not being correct
JopjeKnopje Feb 11, 2024
88c4cfa
Endless tunnel
JopjeKnopje Feb 11, 2024
a30c651
More trippy shit
JopjeKnopje Feb 11, 2024
febadb5
Still not working...
JopjeKnopje Feb 12, 2024
549b593
Back to square one
JopjeKnopje Feb 12, 2024
1fb3e50
HOLY SHIT
JopjeKnopje Feb 12, 2024
e0b6f78
Not there yet but getting close
JopjeKnopje Feb 12, 2024
0cab0ff
fixed rendering of the side of the doors
ys-zm Feb 12, 2024
9cb12c3
Fix minimap weirdness
JopjeKnopje Feb 12, 2024
df7b58b
Kinda works except the door is not filling the enitre tile
Feb 13, 2024
90ac40b
Where we left off
Feb 15, 2024
fb162b8
Trying to draw the rays
Feb 15, 2024
38ccc66
Render all rays in minimap
JopjeKnopje Feb 16, 2024
33cf873
Change color
JopjeKnopje Feb 16, 2024
ae0fcea
Idea kinda clear?
JopjeKnopje Feb 16, 2024
17a70fb
DOORS WORKK (for the y-axis only)
JopjeKnopje Feb 16, 2024
7781d37
Can hit doors in all directions
JopjeKnopje Feb 16, 2024
e6fe5a6
moved to func
JopjeKnopje Feb 16, 2024
a0936c8
Removed the `raycaster_cast_id` function
JopjeKnopje Feb 16, 2024
1590cc6
Rename `rays` to `hrays`
JopjeKnopje Feb 16, 2024
a380d5a
Fixed interactions not working caused by `-ofast` flag
JopjeKnopje Feb 16, 2024
55fb7e0
Kinda fixed door collision
JopjeKnopje Feb 16, 2024
ccb950d
working on adding hud
JopjeKnopje Feb 16, 2024
4a42bf9
Revert "working on adding hud"
JopjeKnopje Feb 23, 2024
219d010
Small stuff norm
JopjeKnopje Feb 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Wonky kinda works
  • Loading branch information
JopjeKnopje committed Feb 9, 2024
commit bdb73959417586a137da5e0f135d422014dd5461
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ SRCS = parser/check_elements.c \
game/floorcaster.c \
game/sprite.c \
game/sprite_utils.c \
game/world.c \
parser/lexer.c \
parser/lexer_utils.c \
parser/map_lexer.c \
Expand All @@ -67,7 +68,10 @@ SRCS = parser/check_elements.c \

HEADER_DIR := include
HEADERS := meta.h \
timer.h
timer.h \
test_utils.h \
vector.h \
parser.h

OBJ_DIR := obj

Expand Down
14 changes: 12 additions & 2 deletions include/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/02/05 14:01:44 by joppe #+# #+# */
/* Updated: 2024/02/09 14:44:08 by joppe ######## odam.nl */
/* Updated: 2024/02/09 16:18:17 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -84,7 +84,6 @@

#define SPRITE_COUNT 2

typedef bool (t_ray_hitfunc) (const void *p, uint32_t x, uint32_t y);

typedef struct s_meta t_meta;

Expand All @@ -96,6 +95,8 @@ MAP_DOOR_OPEN,
MAP_DOOR_CLOSED,
} t_cell_type;

typedef t_cell_type (t_ray_hitfunc) (const void *p, uint32_t x, uint32_t y);

typedef enum e_element_type {
INVALID,
CEIL_FLOOR,
Expand Down Expand Up @@ -147,6 +148,7 @@ typedef struct s_ray {
t_vec2i texture_point;
t_vec2i line_point;
t_side hit_side;
t_cell_type hit_cell;

double line_height;
double length;
Expand All @@ -164,6 +166,7 @@ typedef struct s_player {
t_meta *meta;
t_ray rays[WINDOW_WIDTH];
t_vray vrays[WINDOW_HEIGHT];
t_ray interact_ray;
bool should_render;
t_vec2d cam_plane;
t_vec2d position;
Expand Down Expand Up @@ -241,6 +244,7 @@ typedef struct s_meta {
const char *scene_name;
t_flag *elements;
t_player player;
bool key_states[MLX_KEY_MENU - MLX_KEY_SPACE];
} t_meta;


Expand Down Expand Up @@ -289,6 +293,7 @@ t_ray raycaster_cast(t_vec2d pp, t_vec2d dir, t_ray_hitfunc hit, const void *pa
int32_t set_color(int32_t r, int32_t g, int32_t b, int32_t a);
int32_t find_wall_color(t_attr atrributes, t_ray *ray, t_vec2i line_points, uint32_t h);
int32_t find_color(t_rgba rgba);
mlx_texture_t *get_texture(t_cell_type cell, t_side side, t_attr attributes);

// free.c
void meta_free(t_meta *meta);
Expand Down Expand Up @@ -319,6 +324,7 @@ void print_door_data(t_door doors);

void sprite_sort(double *sprite_dist, int32_t *sprite_order, uint32_t sprite_count);


// lexer.c
char *extract_file(char *map_file);
int lex(char *file, t_map *map, t_flag **elements);
Expand Down Expand Up @@ -346,4 +352,8 @@ int lexer_input_extra(t_flag **extras, char *file, int *skip);



// world.c
void world_interact(t_player *p, t_vec2d map_pos);
bool world_is_interactable(t_cell_type cell);

#endif
11 changes: 10 additions & 1 deletion include/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/18 13:59:19 by jboeve #+# #+# */
/* Updated: 2024/01/18 14:10:07 by jboeve ######## odam.nl */
/* Updated: 2024/02/09 15:21:55 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -17,6 +17,15 @@

#include "meta.h"

static const char *CELL_NAMES[] = {
[MAP_EMPTY] = "MAP_EMPTY",
[MAP_WALL] = "MAP_WALL",
[MAP_SPACE] = "MAP_SPACE",
[MAP_DOOR_OPEN] = "MAP_DOOR_OPEN",
[MAP_DOOR_CLOSED] = "MAP_DOOR_CLOSED",
};



// test_utils.c
void print_cell(t_cell_type cell);
Expand Down
18 changes: 16 additions & 2 deletions src/game/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/08 15:27:07 by yzaim #+# #+# */
/* Updated: 2024/01/18 12:50:58 by jboeve ######## odam.nl */
/* Updated: 2024/02/09 16:00:52 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -52,8 +52,18 @@ static void keys_handle_move(t_meta *meta, double delta_time)
if (pressed)
player_move(p, trans);
}
void render_test(t_meta *meta);

static bool key_pressed(t_meta *meta, keys_t k)
{
bool *state;

state = &meta->key_states[k - MLX_KEY_SPACE];
if (mlx_is_key_down(meta->mlx, k) && !*state)
*state = true;
else if (!mlx_is_key_down(meta->mlx, k) && *state)
*state = false;
return (*state);
}
void keys_handle(t_meta *meta, double delta_time)
{
t_player* const p = &meta->player;
Expand All @@ -67,6 +77,10 @@ void keys_handle(t_meta *meta, double delta_time)
player_turn(p, -rotate_speed);
if (mlx_is_key_down(meta->mlx, MLX_KEY_E))
player_turn(p, rotate_speed);
if (key_pressed(meta, MLX_KEY_F))
player_interact(p);


keys_handle_move(meta, delta_time);
}

Expand Down
63 changes: 60 additions & 3 deletions src/game/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/08 15:27:23 by yzaim #+# #+# */
/* Updated: 2024/02/05 14:03:01 by joppe ######## odam.nl */
/* Updated: 2024/02/09 16:08:32 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -21,11 +21,38 @@
#include <stdio.h>
#include <stdlib.h>

bool bound_check(const void *param, uint32_t x, uint32_t y)
t_cell_type bound_check(const void *param, uint32_t x, uint32_t y)
{
t_meta *const meta = (t_meta *) param;
t_cell_type cur_cell;

if (x < meta->map.width && y < meta->map.height)
{
cur_cell = meta->map.level[(y * meta->map.width) + x];
if (cur_cell == MAP_WALL || cur_cell == MAP_DOOR_CLOSED)
return (cur_cell);
else
return (0);
}
else
{
UNIMPLEMENTED("Map out of bounds.");
}
}

t_cell_type bound_check_interact(const void *param, uint32_t x, uint32_t y)
{
t_meta *const meta = (t_meta *) param;
t_cell_type cur_cell;

if (x < meta->map.width && y < meta->map.height)
return (meta->map.level[(y * meta->map.width) + x] == MAP_WALL || meta->map.level[(y * meta->map.width) + x] == MAP_DOOR_CLOSED);
{
cur_cell = meta->map.level[(y * meta->map.width) + x];
if (cur_cell == MAP_WALL || cur_cell == MAP_DOOR_CLOSED || cur_cell == MAP_DOOR_OPEN)
return (cur_cell);
else
return (0);
}
else
{
UNIMPLEMENTED("Map out of bounds.");
Expand Down Expand Up @@ -89,6 +116,33 @@ void player_turn(t_player *p, float radiant)
player_raycast(p);
}

void player_interact(t_player *p)
{
t_ray *r = &p->interact_ray;

if (((char *) r)[0])
{
printf("ray set\n");
world_interact(p, r->end);
}
}


static void player_interactable_raycast(t_player *p)
{
t_ray *r = &p->interact_ray;
*r = raycaster_cast(p->position, p->direction, bound_check_interact, p->meta);

if (world_is_interactable(r->hit_cell) && r->length < 1.5)
{
// print message to screen
printf("Press F to interact with [%s]\n", CELL_NAMES[r->hit_cell]);
// print_ray("interact ray", r);
}
else
ft_bzero(r, sizeof(t_ray));
}

void player_raycast(t_player *p)
{
uint32_t w = p->meta->image->width;
Expand All @@ -99,6 +153,9 @@ void player_raycast(t_player *p)
double camera_x;



player_interactable_raycast(p);

row = 0;
while (row < h)
{
Expand Down
9 changes: 5 additions & 4 deletions src/game/raycaster.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* raycaster.c :+: :+: */
/* raycaster.c :+: :+: */
/* +:+ */
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/08 15:27:33 by yzaim #+# #+# */
/* Updated: 2024/01/24 13:11:30 by yzaim ######## odam.nl */
/* Updated: 2024/02/09 16:17:54 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -109,15 +109,16 @@ t_ray raycaster_cast(t_vec2d pp, t_vec2d dir, t_ray_hitfunc hit, const void *par
while (limit)
{
r.hit_side = ray_move(&side_dist, &delta_dist, step_size, &r.map_pos);
if (hit && hit(param, r.map_pos.x, r.map_pos.y))
r.hit_cell = hit(param, r.map_pos.x, r.map_pos.y);
// Tmporary
if (hit && r.hit_cell)
break;
limit--;
}
if (!limit)
WARNING("Raycaster limit reached!");
r.length = calculate_ray_length(r.hit_side, side_dist, delta_dist);
r.direction = dir;
// r.end = r.map_pos;

r.line_height = (int)(WINDOW_HEIGHT / r.length);

Expand Down
10 changes: 6 additions & 4 deletions src/game/render_minimap.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/08 15:27:53 by yzaim #+# #+# */
/* Updated: 2024/01/18 12:43:48 by jboeve ######## odam.nl */
/* Updated: 2024/02/09 14:58:33 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -26,9 +26,11 @@
#include <strings.h>

const t_rgba CELL_COLORS[] = {
[MAP_EMPTY] = {MINIMAP_COLOR_BACKGROUND},
[MAP_WALL] = {0x323232ff},
[MAP_SPACE] = {0xcdcdcdff},
[MAP_EMPTY] = {MINIMAP_COLOR_BACKGROUND},
[MAP_WALL] = {0x323232ff},
[MAP_SPACE] = {0xcdcdcdff},
[MAP_DOOR_OPEN] = {0xddddddff},
[MAP_DOOR_CLOSED] = {0x148f91ff},
};


Expand Down
5 changes: 2 additions & 3 deletions src/game/render_viewport.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/08 15:28:08 by yzaim #+# #+# */
/* Updated: 2024/01/25 16:00:13 by jboeve ######## odam.nl */
/* Updated: 2024/02/09 14:55:45 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -17,15 +17,14 @@
#include <stdio.h>
#include <math.h>

mlx_texture_t *get_texture(t_side side, t_attr attributes);

static void draw_column(t_meta *meta, t_ray *ray, uint32_t col, uint32_t h)
{
int32_t y;
int32_t color;
mlx_texture_t *texture;

texture = get_texture(ray->hit_side, meta->attributes);
texture = get_texture(ray->hit_cell, ray->hit_side, meta->attributes);

ray->texture_point.x = (int)(ray->wall_x * texture->width);
if ((ray->hit_side == SIDE_N || ray->hit_side == SIDE_S) && ray->direction.x > 0)
Expand Down
42 changes: 42 additions & 0 deletions src/game/world.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* world.c :+: :+: */
/* +:+ */
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/02/09 14:47:27 by joppe #+# #+# */
/* Updated: 2024/02/09 16:13:33 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

// return if tile your looking at is a door.
#include "meta.h"
#include "vector.h"
#include "parser.h"

void world_is_door(t_ray r)
{

}

void world_door_toggle(t_map *m, t_cell_type cell, size_t index)
{
if (cell == MAP_DOOR_CLOSED)
m->level[index] = MAP_DOOR_OPEN;
else
m->level[index] = MAP_DOOR_CLOSED;
}

void world_interact(t_player *p, t_vec2d map_pos)
{
const size_t index = find_index(p->meta, map_pos.y, map_pos.y);
const t_cell_type cell = p->meta->map.level[index];
world_door_toggle(&p->meta->map, cell, index);
}

bool world_is_interactable(t_cell_type cell)
{
return (cell == MAP_DOOR_CLOSED || cell == MAP_DOOR_OPEN);
}

2 changes: 1 addition & 1 deletion src/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ +:+ +#+*/
/*+#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 18:08:19 by yzaim #+##+# */
/* Updated: 2024/01/29 15:34:19 by yesimzaim ######## odam.nl */
/* Updated: 2024/02/09 15:21:36 by joppe ######## odam.nl */
/**/
/* ************************************************************************** */

Expand Down
Loading