-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite_array.c
101 lines (92 loc) · 2.26 KB
/
sprite_array.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sprite_array.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/21 15:47:59 by lbrandy #+# #+# */
/* Updated: 2021/04/02 20:22:30 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int count_of_sprites(char **map)
{
int i;
int j;
int count;
i = 0;
count = 0;
while (map[i])
{
j = 0;
while (map[i][j])
{
if (map[i][j] == '2')
count++;
j++;
}
i++;
}
return (count);
}
void array_of_sprites(t_all *all, int i)
{
int j;
int k;
k = 0;
all->data_sprite->sprites = (t_sprite *)
malloc(all->data_sprite->count_sprites * sizeof(t_sprite));
if (!all->data_sprite->sprites)
error_handler("malloc error\n");
while (i < all->pos->map_height && all->map[i])
{
j = 0;
while (all->map[i][j])
{
if (all->map[i][j] == '2')
{
all->map[i][j] = 's';
all->data_sprite->sprites[k].x = (double)i;
all->data_sprite->sprites[k].y = (double)j;
k++;
}
j++;
}
i++;
}
}
static void swap(t_sprite *left, t_sprite *right)
{
t_sprite temp;
temp = *right;
*right = *left;
*left = temp;
}
void quick_sort(t_sprite *sprite, int start, int end)
{
int left;
int right;
double center;
left = start;
right = end;
center = sprite[(left + right) / 2].dist;
if (left > right)
return ;
while (left <= right)
{
while (sprite[left].dist > center)
left++;
while (sprite[right].dist < center)
right--;
if (left <= right)
{
if (sprite[left].dist < sprite[right].dist)
swap(&sprite[left], &sprite[right]);
left++;
right--;
}
}
quick_sort(sprite, start, right);
quick_sort(sprite, left, end);
}