-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathText.cpp
179 lines (130 loc) · 5.9 KB
/
Text.cpp
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "Text.hpp"
Text::Text()
{
TTF_Init();
color = {0, 0, 0};
font = TTF_OpenFont("Fonts/mayqueen.ttf", 72); // Possible update would be to make this more dynamic.
score_font = TTF_OpenFont("Fonts/SCRIPTIN.ttf", 16);
}
Text::~Text()
{
TTF_CloseFont(font);
TTF_Quit();
}
void Text::gameOver(SDL_Renderer& render)
{
int siding = sc_wdth / 6;
int flooring = sc_hth / 8;
int mid_w = sc_wdth - (2 * siding);
int mid_l = sc_hth - (2 * flooring);
int top_y_1 = flooring * 2;
int top_x = mid_w / 3;
int top_y_2 = top_y_1 * 2;
string game_pt1 = "Game Over!";
string game_pt2 = "Play Again?";
SDL_Surface* game_pt1_surf = TTF_RenderText_Solid(font, game_pt1.c_str(), color);
SDL_Surface* game_pt2_surf = TTF_RenderText_Solid(font, game_pt2.c_str(), color);
SDL_Texture* game_pt1_text = SDL_CreateTextureFromSurface(&render, game_pt1_surf);
SDL_Texture* game_pt2_text = SDL_CreateTextureFromSurface(&render, game_pt2_surf);
SDL_QueryTexture(game_pt1_text, NULL, NULL, &mid_w, &mid_l);
SDL_QueryTexture(game_pt2_text, NULL, NULL, &mid_w, &mid_l);
SDL_Rect game_pt1_rect;
game_pt1_rect.h = mid_l;
game_pt1_rect.w = mid_w;
game_pt1_rect.x = top_x;
game_pt1_rect.y = top_y_1;
SDL_Rect game_pt2_rect;
game_pt2_rect.h = mid_l;
game_pt2_rect.w = mid_w;
game_pt2_rect.x = top_x;
game_pt2_rect.y = top_y_2;
SDL_RenderCopy(&render, game_pt1_text, NULL, &game_pt1_rect);
SDL_RenderCopy(&render, game_pt2_text, NULL, &game_pt2_rect);
SDL_DestroyTexture(game_pt1_text);
SDL_DestroyTexture(game_pt2_text);
}
void Text::teamSelection(SDL_Renderer& render)
{
int siding = sc_wdth / 6;
int flooring = sc_hth / 8;
int mid_w = sc_wdth - (2 * siding);
int mid_l = sc_hth - (2 * flooring);
int top_y_1 = flooring * 2;
int top_x = mid_w / 3;
int top_y_2 = top_y_1 * 2;
string character_pt1 = "Please Select A Character:";
string character_pt2 = "Press 'B' for Bee and 'W' for Wasp.";
SDL_Surface* character_pt1_surf = TTF_RenderText_Solid(font, character_pt1.c_str(), color);
SDL_Surface* character_pt2_surf = TTF_RenderText_Solid(font, character_pt2.c_str(), color);
SDL_Texture* character_pt1_text = SDL_CreateTextureFromSurface(&render, character_pt1_surf);
SDL_Texture* character_pt2_text = SDL_CreateTextureFromSurface(&render, character_pt2_surf);
SDL_QueryTexture(character_pt1_text, NULL, NULL, &mid_w, &mid_l);
SDL_QueryTexture(character_pt2_text, NULL, NULL, &mid_w, &mid_l);
SDL_Rect character_pt1_rect;
character_pt1_rect.h = mid_l;
character_pt1_rect.w = mid_w;
character_pt1_rect.x = top_x;
character_pt1_rect.y = top_y_1;
SDL_Rect character_pt2_rect;
character_pt2_rect.h = mid_l;
character_pt2_rect.w = mid_w;
character_pt2_rect.x = top_x;
character_pt2_rect.y = top_y_2;
SDL_RenderCopy(&render, character_pt1_text, NULL, &character_pt1_rect);
SDL_RenderCopy(&render, character_pt2_text, NULL, &character_pt2_rect);
SDL_DestroyTexture(character_pt1_text);
SDL_DestroyTexture(character_pt2_text);
}
void Text::displayScore(SDL_Renderer& render, int bee_score, int wasp_score)
{
int siding = sc_wdth / 6;
int flooring = sc_hth / 8;
int mid_w = siding;
int mid_l = flooring;
int w_len = mid_w / 2;
int top_x = siding / 2;
string score_pt1 = "Score: ";
string bee_score_pt2 = to_string(bee_score);
string wasp_score_pt2 = to_string(wasp_score);
SDL_Surface* score_pt1_surf = TTF_RenderText_Solid(font, score_pt1.c_str(), color);
SDL_Surface* bee_score_pt2_surf = TTF_RenderText_Solid(score_font, bee_score_pt2.c_str(), color);
SDL_Surface* wasp_score_pt2_surf = TTF_RenderText_Solid(score_font, wasp_score_pt2.c_str(), color);
SDL_Texture* score_pt1_text = SDL_CreateTextureFromSurface(&render, score_pt1_surf);
SDL_Texture* bee_score_pt2_text = SDL_CreateTextureFromSurface(&render, bee_score_pt2_surf);
SDL_Texture* wasp_score_pt2_text = SDL_CreateTextureFromSurface(&render, wasp_score_pt2_surf);
SDL_QueryTexture(score_pt1_text, NULL, NULL, &w_len, &mid_l);
SDL_QueryTexture(bee_score_pt2_text, NULL, NULL, &mid_w, &mid_l);
SDL_QueryTexture(wasp_score_pt2_text, NULL, NULL, &mid_w, &mid_l);
SDL_Rect bee_score_pt1_rect;
bee_score_pt1_rect.h = mid_l;
bee_score_pt1_rect.w = w_len;
bee_score_pt1_rect.x = siding;
bee_score_pt1_rect.y = flooring;
SDL_Rect wasp_score_pt1_rect;
wasp_score_pt1_rect.h = mid_l;
wasp_score_pt1_rect.w = w_len;
wasp_score_pt1_rect.x = siding * 4;
wasp_score_pt1_rect.y = flooring;
SDL_Rect bee_score_pt2_rect;
bee_score_pt2_rect.h = mid_l;
bee_score_pt2_rect.w = w_len / 4;
bee_score_pt2_rect.x = siding + top_x;
bee_score_pt2_rect.y = flooring;
SDL_Rect wasp_score_pt2_rect;
wasp_score_pt2_rect.h = mid_l;
wasp_score_pt2_rect.w = w_len / 4;
wasp_score_pt2_rect.x = top_x + (siding * 4);
wasp_score_pt2_rect.y = flooring;
SDL_RenderCopy(&render, score_pt1_text, NULL, &bee_score_pt1_rect);
SDL_RenderCopy(&render, bee_score_pt2_text, NULL, &bee_score_pt2_rect);
SDL_RenderCopy(&render, score_pt1_text, NULL, &wasp_score_pt1_rect);
SDL_RenderCopy(&render, wasp_score_pt2_text, NULL, &wasp_score_pt2_rect);
SDL_DestroyTexture(score_pt1_text);
SDL_DestroyTexture(bee_score_pt2_text);
SDL_DestroyTexture(wasp_score_pt2_text);
}
void Text::getScreenArea(int sc_h, int sc_w)
{
sc_hth = sc_h;
sc_wdth = sc_w;
}