Skip to content

Commit

Permalink
added door tex
Browse files Browse the repository at this point in the history
  • Loading branch information
ys-zm committed Feb 9, 2024
1 parent 22ae619 commit b5c7ad8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void print_double_array(char *msg, double *arr, uint32_t size, t_sprite *sp, int
void print_ints_array(char *msg, int32_t *arr, uint32_t size);
void print_sprites_array(t_sprite *arr, uint32_t size);
void print_attributes(t_attr *attributes);

void print_door_data(t_door doors);
// sprite_utils.c

void sprite_sort(double *sprite_dist, int32_t *sprite_order, uint32_t sprite_count);
Expand Down
2 changes: 0 additions & 2 deletions src/game/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,4 @@ void player_raycast(t_player *p)
}

sprite_calculate(p);


}
4 changes: 3 additions & 1 deletion src/game/render_viewport.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void render_viewport(mlx_image_t *image, t_player *p)
draw_column(p->meta, &p->rays[col], col, image->height);
col++;
}
// render sprites

// render doors


}
2 changes: 1 addition & 1 deletion src/parser/parse_elements.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int input_sprite_texture_path(t_sprite **sprites_array, uint32_t *i ,char *conte

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

Expand Down
13 changes: 13 additions & 0 deletions src/set_textures.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ int set_sprite_textures(uint32_t sprite_count, t_sprite *sprites)
return (EXIT_SUCCESS);
}

int set_door_texture(t_door *doors)
{
if (doors->door_count)
{
doors->tex.tex = mlx_load_png(doors->tex.tex_path);
if (doors->tex.tex == NULL)
return (EXIT_FAILURE);
}
return (EXIT_SUCCESS);
}

int set_textures(t_attr *attributes)
{
attributes->n.tex = mlx_load_png(attributes->n.tex_path);
Expand All @@ -72,6 +83,8 @@ int set_textures(t_attr *attributes)
return (pr_err(MLX_ERROR));
if (set_sprite_textures(attributes->sprite_count, attributes->sprites))
return (pr_err(MLX_ERROR));
if (set_door_texture(&attributes->doors))
return (pr_err(MLX_ERROR));
return (EXIT_SUCCESS);
}

17 changes: 17 additions & 0 deletions src/test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,21 @@ void print_attributes(t_attr *attributes)
printf("C: %s\n", attributes->c.tex_path);
else
printf("C: %d,%d,%d\n", attributes->ceiling_c.r, attributes->ceiling_c.g, attributes->ceiling_c.b);
}

void print_door_data(t_door doors)
{
int i = 0;
printf("DOOR COUNT: %u\n", doors.door_count);
printf("DOOR TEX: %s\n", doors.tex.tex_path);
while (i < doors.door_count)
{
if (i == 0)
printf("DOOR IDX: ");
printf("%u", doors.idx[i]);
if (i < doors.door_count - 1)
printf(" | ");
i++;
}
printf("\n");
}
5 changes: 2 additions & 3 deletions test_maps/valid_tex.cub
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ C texture_examples/ceiling_square.png

SP texture_examples/pillar.png 4.5 2.5
SP texture_examples/barrel.png 5.5 3.5
SP texture_examples/hoofd.png 2.5 3.5
SP texture_examples/sexy.png 2.5 2.5
DR texture_examples/door.png

11111111111111
1000000001
1000000001
1000000001
1000000001
10000000D1
100000000111
111000N00111
100000000001
Expand Down
Binary file added texture_examples/door.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b5c7ad8

Please sign in to comment.