Skip to content

Commit

Permalink
sprites dont go through walls anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesim Zaim committed Feb 8, 2024
1 parent 7fea4ea commit a3d4a3c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"files.associations": {
"cstdlib": "c",
"stdio.h": "c",
"meta.h": "c"
"meta.h": "c",
"array": "c",
"string_view": "c",
"initializer_list": "c",
"ranges": "c",
"span": "c",
"utility": "c"
}
}
4 changes: 2 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/08 13:54:31 by yzaim ######## odam.nl */
/* Updated: 2024/02/08 15:08:42 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -309,7 +309,7 @@ void sprite_calculate(t_player *p);

// test_utils.c REMOVE LATER

void print_double_array(char *msg, double *arr, uint32_t size);
void print_double_array(char *msg, double *arr, uint32_t size, t_sprite *sp, int32_t *order);
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);
Expand Down
10 changes: 5 additions & 5 deletions src/game/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/25 16:01:20 by jboeve #+# #+# */
/* Updated: 2024/02/08 14:09:34 by yzaim ######## odam.nl */
/* Updated: 2024/02/08 15:09:00 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -53,13 +53,15 @@ void sprite_calculate(t_player *p)
while (i < p->meta->attributes.sprite_count)
{
p->sprite_order[i] = i;
p->sprite_dist[i] = (p->position.x - p->meta->attributes.sprites[i].pos.x) * (p->position.x - p->meta->attributes.sprites[i].pos.x) + (p->position.y - p->meta->attributes.sprites[i].pos.y) * (p->position.y - p->meta->attributes.sprites[i].pos.y);
t_vec2d sp_pos = p->meta->attributes.sprites[i].pos;
p->sprite_dist[i] = ((p->position.x - sp_pos.x) * (p->position.x - sp_pos.x)) + ((p->position.y - sp_pos.y) * (p->position.y - sp_pos.y));
i++;
}

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);
print_ints_array("SPRITE ORDER", p->sprite_order, p->meta->attributes.sprite_count);
print_double_array("SPRITE DIST", p->sprite_dist, p->meta->attributes.sprite_count, p->meta->attributes.sprites, p->sprite_order);

i = 0;
while (i < p->meta->attributes.sprite_count)
Expand All @@ -69,8 +71,6 @@ void sprite_calculate(t_player *p)


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

printf("invdet [%lf]\n", inv_det);

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
6 changes: 3 additions & 3 deletions src/game/sprite_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/25 16:01:20 by jboeve #+# #+# */
/* Updated: 2024/02/08 14:06:22 by yzaim ######## odam.nl */
/* Updated: 2024/02/08 15:13:24 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -52,7 +52,7 @@ uint32_t partition(double *sprite_dist, int32_t *sprite_order, int32_t low, int3
}
}
swap_doubles(&sprite_dist[low], &sprite_dist[j]);
swap_ints(&sprite_order[low], &sprite_order[i]);
swap_ints(&sprite_order[low], &sprite_order[j]);
return (j);
}

Expand Down Expand Up @@ -88,5 +88,5 @@ void reverse(double *arr1, int32_t *arr2, uint32_t size)
void sprite_sort(double *sprite_dist, int32_t *sprite_order, uint32_t sprite_count)
{
quick_sort(sprite_dist, sprite_order, 0, sprite_count - 1);
// reverse(sprite_dist, sprite_order, sprite_count);
reverse(sprite_dist, sprite_order, sprite_count);
}
26 changes: 17 additions & 9 deletions src/test_utils.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_utils.c :+: :+: */
/* +:+ +:+ +:+ */
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/08 15:25:38 by yzaim #+# #+# */
/* Updated: 2024/01/26 16:10:28 by yzaim ######## odam.nl */
/* :::::::: */
/* test_utils.c :+: :+: */
/* +:+ */
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/08 15:25:38 by yzaim #+# #+# */
/* Updated: 2024/02/08 15:08:32 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -77,16 +77,24 @@ void print_map_cell(t_cell_type *level, uint32_t w, uint32_t h)
}
}

void print_double_array(char *msg, double *arr, uint32_t size)
void print_double_array(char *msg, double *arr, uint32_t size, t_sprite *sp, int32_t *order)
{
printf("%s :", msg);
printf("%s: ", msg);
for (int i = 0; i < size; i++)
{
printf("%lf", arr[i]);
if (i < size - 1)
printf(" | ");
}
printf("\n");
printf("TEXTURES: ");
for (int i = 0; i < size; i++)
{
printf("%s", sp[order[i]].tex.tex_path + 17);
if (i < size - 1)
printf(" | ");
}
printf("\n");
}

void print_ints_array(char *msg, int32_t *arr, uint32_t size)
Expand Down
6 changes: 2 additions & 4 deletions test_maps/valid_tex.cub
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ F texture_examples/floor.png
C texture_examples/ceiling_square.png

SP texture_examples/pillar.png 4.5 2.5
SP texture_examples/barrel.png 5.5 2.5
SP texture_examples/hoofd.png 6.5 2.5
SP texture_examples/sexy.png 7.5 2.5
SP texture_examples/barrel.png 5.5 3.5

11111111111111
1000000001
1000000001
1000000001
1000000001
1111101111
100000000111
111000N00111
100000000001
10000000011
Expand Down

0 comments on commit a3d4a3c

Please sign in to comment.