Skip to content

Commit

Permalink
parser for doors kinda working
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesim Zaim committed Feb 8, 2024
1 parent b9f60d6 commit 2a948cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
24 changes: 9 additions & 15 deletions include/meta.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* meta.h :+: :+: */
/* +:+ */
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* :::::::: */
/* meta.h :+: :+: */
/* +:+ */
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/02/05 14:01:44 by joppe #+# #+# */
/* Updated: 2024/02/05 14:01:52 by joppe ######## odam.nl */
/* Updated: 2024/02/08 12:52:25 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */



#ifndef META_H
#define META_H

Expand Down Expand Up @@ -52,7 +50,6 @@

#define PI 3.1415926535


// Window
// #define WINDOW_WIDTH 1920
// #define WINDOW_HEIGHT 1080
Expand All @@ -61,7 +58,6 @@

#define BPP 4


// Game
#define TICK_RATE (1.0 / 60.0)

Expand Down Expand Up @@ -100,11 +96,12 @@ MAP_DOOR
} t_cell_type;

typedef enum e_element_type {
INVALID,
CEIL_FLOOR,
WALL,
SPRITE,
DOOR,
NON_VALID
DOOR_CL,
DOOR_OP
} t_element_type;

typedef enum e_font_family {
Expand All @@ -124,7 +121,6 @@ typedef struct s_font_atlas
char *pixels;
} t_font_atlas;


typedef union s_rgba
{
uint32_t value;
Expand All @@ -137,7 +133,6 @@ typedef union s_rgba
};
} t_rgba;


typedef enum e_side {
SIDE_N = 0,
SIDE_S = 1,
Expand Down Expand Up @@ -179,7 +174,6 @@ typedef struct s_player {
double z_buffer[WINDOW_WIDTH];
} t_player;


typedef struct s_map {
char *map_element;
t_cell_type *level;
Expand Down
18 changes: 7 additions & 11 deletions src/game/sprite.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* sprite.c :+: :+: */
/* +:+ */
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* :::::::: */
/* sprite.c :+: :+: */
/* +:+ */
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/25 16:01:20 by jboeve #+# #+# */
/* Updated: 2024/02/07 12:48:55 by yzaim ######## odam.nl */
/* Updated: 2024/02/08 13:06:59 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -59,18 +59,14 @@ void sprite_calculate(t_player *p)

sprite_sort(p->sprite_dist, p->sprite_order, p->meta->attributes.sprite_count);

// print_double_array("SPRITE DIST", p->sprite_dist, p->meta->attributes.sprite_count);

i = 0;
while (i < p->meta->attributes.sprite_count)
{
const t_sprite *sp = p->meta->attributes.sprites;
const t_vec2d s_pos = (t_vec2d){sp[p->sprite_order[i]].pos.x - p->position.x, sp[p->sprite_order[i]].pos.y - p->position.y};


const double inv_det = 1.0 / (p->cam_plane.x * p->direction.y) - (p->cam_plane.y * p->direction.x);


double inv_det = 1.0 / (p->cam_plane.x * p->direction.y) - (p->cam_plane.y * p->direction.x);
const t_vec2d transform = {inv_det * (p->direction.y * s_pos.x - p->direction.x * s_pos.y),
inv_det * (-(p->cam_plane.y) * s_pos.x + p->cam_plane.x * s_pos.y)};

Expand Down
10 changes: 5 additions & 5 deletions src/parser/parse_elements.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:43:19 by yzaim #+# #+# */
/* Updated: 2024/02/08 12:35:25 by yzaim ######## odam.nl */
/* Updated: 2024/02/08 12:54:47 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -58,8 +58,8 @@ t_element_type check_element_type(char *flag)
if (!ft_strncmp(flag, "SP", 2))
return (SPRITE);
if (!ft_strncmp(flag, "DR", 2))
return (DOOR);
return (NON_VALID);
return (DOOR_CL);
return (INVALID);
}

int handle_ceil_floor(t_attr *attributes, char *flag, char *content)
Expand Down Expand Up @@ -150,7 +150,7 @@ int handle_element(t_meta *meta, t_element_type type, char *flag, char *content)
{
exit_code = input_sprite_texture_path(&meta->attributes.sprites, &meta->attributes.sprite_arr_index, content);
}
else if (type == DOOR)
else if (type == DOOR_CL)
{
exit_code = input_door_path(&meta->attributes.doors, content);
}
Expand Down Expand Up @@ -232,7 +232,7 @@ int parse_elements(t_meta *meta)
while (elements != NULL)
{
t_element_type type = check_element_type(elements->flag);
if (type != NON_VALID)
if (type != INVALID)
handle_element(meta, type, elements->flag, elements->content);
elements = elements->next;
}
Expand Down

0 comments on commit 2a948cf

Please sign in to comment.