Skip to content

Commit

Permalink
applying doors
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesim Zaim committed Feb 7, 2024
1 parent 99e0d22 commit 18f2d40
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
8 changes: 4 additions & 4 deletions include/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ typedef struct s_sprite {
} t_sprite;

typedef struct s_door {
uint32_t door_count;
t_tex tex;
uint32_t idx;
}
uint32_t *idx;
} t_door;

typedef struct s_attr {
t_tex n; //add bit flag, if tex_path is missing then it means it is a color value
Expand All @@ -224,8 +225,7 @@ typedef struct s_attr {
uint32_t sprite_count;
uint32_t sprite_arr_index;
t_sprite *sprites; // we need to make the sprite count modular
uint32_t door_count;
t_door *doors;
t_door doors;
} t_attr;

typedef struct s_minimap {
Expand Down
37 changes: 30 additions & 7 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/01/24 11:21:34 by yzaim ######## odam.nl */
/* Updated: 2024/02/07 16:42:32 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -132,6 +132,11 @@ int input_sprite_texture_path(t_sprite **sprites_array, uint32_t *i ,char *conte
return (EXIT_SUCCESS);
}

int input_door_path(t_door *doors, char *content)
{
doors->tex.tex_path = content;
}

int handle_element(t_meta *meta, t_element_type type, char *flag, char *content)
{
int exit_code;
Expand All @@ -143,7 +148,10 @@ int handle_element(t_meta *meta, t_element_type type, char *flag, char *content)
else if (type == SPRITE)
{
exit_code = input_sprite_texture_path(&meta->attributes.sprites, &meta->attributes.sprite_arr_index, content);
// printf("%d. SP %s %lf %lf\n", 0, meta->attributes.sprites[0].tex.tex_path, meta->attributes.sprites[0].pos.x, meta->attributes.sprites[0].pos.y);
}
else if (type == DOOR)
{
exit_code = input_door_path(&meta->attributes.doors, content)
}
return (exit_code);
}
Expand Down Expand Up @@ -175,17 +183,29 @@ uint32_t count_doors(t_cell_type *map, uint32_t w, uint32_t h)
return (doors);
}

int save_index(t_door *doors, uint32_t door_count)
int save_door_index(uint32_t arr, uint32_t door_count, t_map map)
{
uint32_t i;
uint32_t j;

j = 0;
i = 0;
while (i < map.width * map.height)
{
if (map[i] == MAP_DOOR)
{
arr[j].idx = i;
if (j < door_count)
j++;
}
i++;
}
}

int set_doors(t_meta *meta)
{
meta.attributes.doors = malloc(sizeof(t_door) * meta.attributes.door_count);
if (!meta.attributes.doors)
meta.attributes.doors.idx = malloc(sizeof(uint32_t) * meta.attributes.door_count);
if (!meta.attributes.doors.idx)
return (pr_err(MALL_ERR));

}
Expand All @@ -194,11 +214,14 @@ int parse_elements(t_meta *meta)
{
t_flag *elements = meta->elements;
meta->attributes.sprite_count = count_sprites(meta->elements);
meta.attributes.door_count = count_doors(meta.map.level, meta.map.width, meta.map.height);
meta.attributes.doors.door_count = count_doors(meta.map.level, meta.map.width, meta.map.height);
meta->attributes.sprite_arr_index = 0;

if (meta.attributes.door_count)
if (meta.attributes.doors.door_count)
{
if(set_doors(meta) || save_door_index(meta.attributes.doors.idx, meta.attributes.doors.door_count, meta.map))
return (EXIT_FAILURE);

// save door idx
}
if (set_up_sprites(meta))
Expand Down

0 comments on commit 18f2d40

Please sign in to comment.