-
Notifications
You must be signed in to change notification settings - Fork 0
/
face.c
131 lines (122 loc) · 4.16 KB
/
face.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* face.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhedeon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/27 22:02:18 by mhedeon #+# #+# */
/* Updated: 2019/01/31 17:25:44 by mhedeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
static void draw_face_2(t_wolf *wolf, t_texture *face, int time, int ticks)
{
if ((time - ticks) < 5000)
draw_cursor(wolf, face + 5, &(SDL_Rect) { SCREEN_WIDTH / 2 - 2 *
(face + 5)->sur->w,
SCREEN_HEIGHT - (face + 5)->sur->h, (face + 5)->sur->w,
(face + 5)->sur->h });
else if ((time - ticks) < 6000)
draw_cursor(wolf, face + 6, &(SDL_Rect) { SCREEN_WIDTH / 2 - 2 *
(face + 6)->sur->w,
SCREEN_HEIGHT - (face + 6)->sur->h, (face + 6)->sur->w,
(face + 6)->sur->h });
else if ((time - ticks) < 7000)
draw_cursor(wolf, face + 7, &(SDL_Rect) { SCREEN_WIDTH / 2 - 2 *
(face + 7)->sur->w,
SCREEN_HEIGHT - (face + 7)->sur->h, (face + 7)->sur->w,
(face + 7)->sur->h });
else if ((time - ticks) < 8000)
draw_cursor(wolf, face + 8, &(SDL_Rect) { SCREEN_WIDTH / 2 - 2 *
(face + 8)->sur->w,
SCREEN_HEIGHT - (face + 8)->sur->h, (face + 8)->sur->w,
(face + 8)->sur->h });
}
static void draw_face(t_wolf *wolf, t_texture *face, int time)
{
static int ticks = 0;
ticks = time - ticks >= 8000 ? SDL_GetTicks() : ticks;
if ((time - ticks) < 1000)
draw_cursor(wolf, face + 1, &(SDL_Rect) { SCREEN_WIDTH / 2 - 2 *
(face + 1)->sur->w, SCREEN_HEIGHT - (face + 1)->sur->h,
(face + 1)->sur->w, (face + 1)->sur->h });
else if ((time - ticks) < 2000)
draw_cursor(wolf, face + 2, &(SDL_Rect) { SCREEN_WIDTH / 2 - 2 *
(face + 2)->sur->w,
SCREEN_HEIGHT - (face + 2)->sur->h, (face + 2)->sur->w,
(face + 2)->sur->h });
else if ((time - ticks) < 3000)
draw_cursor(wolf, face + 3, &(SDL_Rect) { SCREEN_WIDTH / 2 - 2 *
(face + 3)->sur->w,
SCREEN_HEIGHT - (face + 3)->sur->h, (face + 3)->sur->w,
(face + 3)->sur->h });
else if ((time - ticks) < 4000)
draw_cursor(wolf, face + 4, &(SDL_Rect) { SCREEN_WIDTH / 2 - 2 *
(face + 4)->sur->w,
SCREEN_HEIGHT - (face + 4)->sur->h, (face + 4)->sur->w,
(face + 4)->sur->h });
else
draw_face_2(wolf, face, time, ticks);
}
void face(t_wolf *wolf)
{
if (wolf->hero->health <= 15)
draw_face(wolf, wolf->face + 60, SDL_GetTicks());
else if (wolf->hero->health > 15 && wolf->hero->health <= 30)
draw_face(wolf, wolf->face + 50, SDL_GetTicks());
else if (wolf->hero->health > 30 && wolf->hero->health <= 45)
draw_face(wolf, wolf->face + 40, SDL_GetTicks());
else if (wolf->hero->health > 45 && wolf->hero->health <= 60)
draw_face(wolf, wolf->face + 30, SDL_GetTicks());
else if (wolf->hero->health > 60 && wolf->hero->health <= 75)
draw_face(wolf, wolf->face + 20, SDL_GetTicks());
else if (wolf->hero->health > 75 && wolf->hero->health <= 90)
draw_face(wolf, wolf->face + 10, SDL_GetTicks());
else if (wolf->hero->health > 90)
draw_face(wolf, wolf->face + 0, SDL_GetTicks());
}
int load_face(t_texture *face)
{
int i;
int j;
char *tmp[2];
j = 10;
while (j <= 70)
{
i = 0;
while (++i <= 8)
{
tmp[0] = ft_itoa(j + i);
tmp[1] = ft_strjoin(tmp[0], ".png");
free(tmp[0]);
tmp[0] = ft_strjoin("resource/img/face/", tmp[1]);
free(tmp[1]);
if (!load_texture(&face[j - 10 + i], tmp[0]))
{
free(tmp[0]);
return (0);
}
free(tmp[0]);
}
j += 10;
}
return (1);
}
int free_face(t_texture *face)
{
int i;
int j;
j = 10;
while (j <= 70)
{
i = 0;
while (++i <= 8)
{
if (face[j - 10 + i].sur != NULL)
destroy_texture(&face[j - 10 + i]);
}
j += 10;
}
return (0);
}