-
Notifications
You must be signed in to change notification settings - Fork 0
/
hud.c
104 lines (95 loc) · 3.24 KB
/
hud.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hud.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhedeon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/31 16:33:46 by mhedeon #+# #+# */
/* Updated: 2019/01/31 17:29:22 by mhedeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
static void show_health(t_wolf *wolf, SDL_Rect r)
{
char *tmp;
char *tmp2;
SDL_Surface *sur;
SDL_Texture *message;
tmp2 = ft_itoa(wolf->hero->health);
tmp = ft_strjoin("+", tmp2);
sur = TTF_RenderText_Solid(wolf->font, tmp,
(SDL_Color) {255, 255, 255, 255});
message = SDL_CreateTextureFromSurface(wolf->ren, sur);
SDL_GetWindowSize(wolf->win, &r.x, &r.y);
r.w = r.x / 10;
r.h = r.x / 10;
SDL_RenderCopy(wolf->ren, message, NULL, &(SDL_Rect)
{r.x / 2 - 2.5 * r.w, r.y - r.h, r.w, r.h});
free(tmp);
free(tmp2);
SDL_FreeSurface(sur);
SDL_DestroyTexture(message);
}
static void show_bullet(t_wolf *wolf, SDL_Rect r)
{
char *tmp;
char *tmp2;
SDL_Surface *sur;
SDL_Texture *message;
tmp2 = ft_itoa(wolf->hero->bullet);
tmp = ft_strjoin("\%", tmp2);
sur = TTF_RenderText_Solid(wolf->font, tmp,
(SDL_Color) {255, 255, 255, 255});
message = SDL_CreateTextureFromSurface(wolf->ren, sur);
SDL_GetWindowSize(wolf->win, &r.x, &r.y);
r.w = 2 * r.x / 10;
r.h = r.x / 10;
SDL_RenderCopy(wolf->ren, message, NULL, &(SDL_Rect)
{r.x / 2 + 0.75 * r.w, r.y - r.h * 0.80, r.w, r.h});
free(tmp);
free(tmp2);
SDL_FreeSurface(sur);
SDL_DestroyTexture(message);
}
static void show_score(t_wolf *wolf, SDL_Rect r)
{
char *tmp;
SDL_Surface *sur;
SDL_Texture *message;
tmp = ft_itoa(wolf->hero->score);
sur = TTF_RenderText_Solid(wolf->font, tmp,
(SDL_Color) {255, 255, 255, 255});
message = SDL_CreateTextureFromSurface(wolf->ren, sur);
SDL_GetWindowSize(wolf->win, &r.x, &r.y);
r.w = r.x / 10;
r.h = r.x / 10;
SDL_RenderCopy(wolf->ren, message, NULL,
&(SDL_Rect) {50, r.y - r.h, r.w, r.h});
free(tmp);
SDL_FreeSurface(sur);
SDL_DestroyTexture(message);
}
void draw_hud(t_wolf *wolf)
{
face(wolf);
SDL_UpdateTexture(HUD);
SDL_RenderClear(wolf->ren);
SDL_RenderCopy(wolf->ren, wolf->tex, NULL, NULL);
show_score(wolf, (SDL_Rect) { 0, 0, 0, 0 });
show_bullet(wolf, (SDL_Rect) { 0, 0, 0, 0 });
show_health(wolf, (SDL_Rect) { 0, 0, 0, 0 });
SDL_RenderPresent(wolf->ren);
}
void draw_hud_lvl3(t_wolf *wolf)
{
face(wolf);
SDL_UpdateTexture(HUD);
SDL_RenderClear(wolf->ren);
SDL_RenderCopy(wolf->ren, wolf->tex, NULL, NULL);
show_score(wolf, (SDL_Rect) { 0, 0, 0, 0 });
show_bullet(wolf, (SDL_Rect) { 0, 0, 0, 0 });
show_health(wolf, (SDL_Rect) { 0, 0, 0, 0 });
dist_lvl_3(wolf, (SDL_Rect) { 0, 0, 0, 0 });
SDL_RenderPresent(wolf->ren);
}