Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
animations.cpp
Go to the documentation of this file.
1#include <iostream>
2#include "raylib.h"
3#include "timer.h"
4#include "animations.h"
5#include "travelLogic.h"
6#include "quizLogic.h"
7#include "cityOperations.h"
8
12void drawActiveCityAnimation(ActiveCityAnimationFrame* activeCityAnimationParts, City activeCity)
13{
14 // Variable to store the animations frames
15 int opr = 0;
16
17 // Update animation frame color, based on circles' radius
18 for (int i = 0; i < 3; i++)
19 {
20 // Translate circles' radius to int
21 opr = int(activeCityAnimationParts[i].size);
22
23 // Change the color's opacity based on the circles' radius
24 switch (opr)
25 {
26 case 5:
27 activeCityAnimationParts[i].color = frame1;
28 break;
29 case 7:
30 activeCityAnimationParts[i].color = frame2;
31 break;
32 case 8:
33 activeCityAnimationParts[i].color = frame3;
34 break;
35 case 10:
36 activeCityAnimationParts[i].color = frame4;
37 break;
38 case 11:
39 activeCityAnimationParts[i].color = frame5;
40 break;
41 case 12:
42 activeCityAnimationParts[i].color = frame6;
43 break;
44 case 14:
45 activeCityAnimationParts[i].color = frame7;
46 break;
47 case 16:
48 activeCityAnimationParts[i].color = frame8;
49 break;
50 case 17:
51 activeCityAnimationParts[i].color = frame9;
52 break;
53 case 19:
54 case 20:
55 activeCityAnimationParts[i].color = frame10;
56 break;
57 }
58 }
59
60 // Active city animation
61 for (int i = 0; i < 3; i++)
62 {
63 // Draw the 3 circles
64 DrawCircleV(Vector2{ activeCity.coordinates.x, activeCity.coordinates.y - float(3) }, activeCityAnimationParts[i].size, activeCityAnimationParts[i].color);
65
66 // Check for circle radius update direction (+, -)
67 if (activeCityAnimationParts[i].direction == '+')
68 {
69 // Upadate circle radius
70 activeCityAnimationParts[i].size += float(0.07);
71
72 // Reverse update director when radius reaches maximum(15)
73 if (activeCityAnimationParts[i].size >= 20)
74 {
75 activeCityAnimationParts[i].direction = '-';
76 }
77 }
78
79 // Check for circle radius update direction (+, -)
80 if (activeCityAnimationParts[i].direction == '-')
81 {
82 // Upadate circle radius
83 activeCityAnimationParts[i].size -= float(0.07);
84
85 // Reverse update director when radius reaches minimum(5)
86 if (activeCityAnimationParts[i].size <= 5)
87 {
88 activeCityAnimationParts[i].direction = '+';
89 }
90 }
91 }
92}
93
97void drawPopUpAnimationBottom(PopUpAnimationFrame* componentPtr, float endY, bool showComponent)
98{
99 // Check if pop-up component should be extended ot retracted
100 if (showComponent)
101 {
102 // Update animation state to -1(decreasing)
103 componentPtr->state = -1;
104 }
105 else if (!showComponent)
106 {
107 // Update animation state to 1(increasing)
108 componentPtr->state = 1;
109 }
110
111 // Update target position based on animation state
112 switch (componentPtr->state)
113 {
114 // Update target position in decreasing state
115 case -1:
116 componentPtr->pos.y -= 2.5;
117
118 // Check for top animation boundary
119 if (componentPtr->pos.y <= endY)
120 {
121 // Snap target to boundary
122 componentPtr->pos.y = endY;
123
124 // Update animation state to 0(paused)
125 componentPtr->state = 0;
126 }
127 break;
128
129 // Update target position in increasing state
130 case 1:
131 componentPtr->pos.y += 2.5;
132
133 // Check for bottom animation boundary
134 if (componentPtr->pos.y >= 1080)
135 {
136 // Snap target to boundary
137 componentPtr->pos.y = 1080;
138
139 // Update animation state to 0(paused)
140 componentPtr->state = 0;
141 }
142 break;
143
144 // Account for the paused animation state
145 default:
146 break;
147 }
148
149 // Draw pop-up menu
150 DrawTextureV(componentPtr->texture, componentPtr->pos, RAYWHITE);
151}
152
156void drawPopUpAnimationSide(PopUpAnimationFrame* quizPtr, Texture2D texture, bool showQuiz)
157{
158 // Check if pop-up component should be extended ot retracted
159 if (showQuiz)
160 {
161 // Update animation state to -1(decreasing)
162 quizPtr->state = -1;
163 }
164 else if (!showQuiz)
165 {
166 // Update animation state to 1(increasing)
167 quizPtr->state = 1;
168 }
169
170 // Update target position based on animation state
171 switch (quizPtr->state)
172 {
173 // Update target position in decreasing state
174 case -1:
175 quizPtr->pos.x -= 2.5;
176
177 // Check for top animation boundary
178 if (quizPtr->pos.x <= 956)
179 {
180 // Snap target to boundary
181 quizPtr->pos.x = 956;
182
183 // Update animation state to 0(paused)
184 quizPtr->state = 0;
185 }
186 break;
187
188 // Update target position in increasing state
189 case 1:
190 quizPtr->pos.x += 2.5;
191
192 // Check for top animation boundary
193 if (quizPtr->pos.x >= 1920)
194 {
195 // Snap target to boundary
196 quizPtr->pos.x = 1920;
197
198 // Update animation state to 0(paused)
199 quizPtr->state = 0;
200 }
201 break;
202
203 // Account for the paused animation state
204 default:
205 break;
206 }
207
208 DrawTextureV(texture, quizPtr->pos, RAYWHITE);
209}
210
214void drawPopUpMenuHover(Rectangle confirmHitbox, Rectangle denyHitbox, Texture2D confirmHover, Texture2D denyHover, PopUpAnimationFrame* popUpAnimationFramePtr)
215{
216 // Check if pop-up is fully extended
217 if (popUpAnimationFramePtr->pos.y == 913)
218 {
219 // Check if the mouse is hovering over the confirm button
220 if (CheckCollisionPointRec(Vector2(GetMousePosition()), confirmHitbox))
221 {
222 // Draw confirm button hover effect
223 DrawTexture(confirmHover, 1434, 985, RAYWHITE);
224 }
225 // Check if the mouse is hovering over the deny button
226 else if (CheckCollisionPointRec(Vector2(GetMousePosition()), denyHitbox))
227 {
228 // Draw deny button hover effect
229 DrawTexture(denyHover, 1666, 985, RAYWHITE);
230 }
231 }
232}
233
237void manageWarningAnimation(Vector2 mousePoint, City cities[40], City activeCity, PopUpAnimationFrame* warningAnimationFramePtr, PopUpAnimationFrame popUpMenuFrame, Timer* warningTimerPtr, float* warningScreentimePtr, bool* wariningVisiblePtr, bool showPopUpMenu)
238{
239 // Check if a visited city is clicked
240 for (int i = 0; i < 40; i++)
241 {
242 if (CheckCollisionPointRec(mousePoint, Rectangle{ cities[i].hitbox.x - (cities[i].hitbox.width / 2), cities[i].hitbox.y - (cities[i].hitbox.height / 2), cities[i].hitbox.width, cities[i].hitbox.height }))
243 {
244 // Check if selected city is visited
245 if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && cities[i].name != activeCity.name && cities[i].wasVisited == true)
246 {
247 // Reset warning time each time a visited city is clicked
248 *warningScreentimePtr = 2.5f;
249
250 // Start up the timer with the reset screentime
251 StartTimer(warningTimerPtr, *warningScreentimePtr);
252 }
253 }
254 }
255
256 // Tick timer
257 UpdateTimer(warningTimerPtr);
258
259 // Check if the timer hasn't expired
260 if (!TimerDone(warningTimerPtr))
261 {
262 // Allow the warningAlert to be drawn
263 *wariningVisiblePtr = true;
264 }
265 else
266 {
267 // Restrict the drawing of the warningAlert
268 *wariningVisiblePtr = false;
269 }
270
271 // Check if the pop-up menu is drawn
272 if (!showPopUpMenu && popUpMenuFrame.pos.y == 1080)
273 {
274 // Update the warning's position if the pop-up menu is retracted
275 warningAnimationFramePtr->pos.x = 1475;
276 }
277 else
278 {
279 // Keep original posion next to the pop-up menu
280 warningAnimationFramePtr->pos.x = 936;
281 }
282}
283
287void drawOptionComponent(Option options[4], Texture2D texture, float x, float y, int index, int i)
288{
289 // Check for and fix minor line disposition
290 if ((i == 0 || i == 1) && index != 0 && index != 25 && index != 35 && index != 30 && index != 20 && index != 10 && index != 15)
291 {
292 // Draw option hover effect
293 DrawTextureV(texture, Vector2{ x - 2, y - 1 }, RAYWHITE);
294 }
295 else if (index != 0)
296 {
297 // Draw option hover effect
298 DrawTextureV(texture, Vector2{ x - 2, y - 2 }, RAYWHITE);
299 }
300
301 // Check for and fix minor line disposition
302 if (index == 0)
303 {
304 if (i == 0 || i == 1)
305 {
306 // Draw option hover effect
307 DrawTextureV(texture, Vector2{ x - 5, y - 4 }, RAYWHITE);
308 }
309 else
310 {
311 // Draw option hover effect
312 DrawTextureV(texture, Vector2{ x - 5, y - 5 }, RAYWHITE);
313 }
314 }
315
316 // Check for and fix minor line disposition
317 if (index == 25 || index == 35 || index == 30 || index == 20 || index == 10 || index == 15)
318 {
319 if (i == 0 || i == 1)
320 {
321 // Draw option hover effect
322 DrawTextureV(texture, Vector2{ x - 3, y - 1 }, RAYWHITE);
323 }
324 else
325 {
326 // Draw option hover effect
327 DrawTextureV(texture, Vector2{ x - 3, y - 2 }, RAYWHITE);
328 }
329 }
330}
331
335void drawQuizOptionsHover(Option options[4], PopUpAnimationFrame quizAnimationFrame, int index)
336{
337 // Check if quiz window is fully extended
338 if (quizAnimationFrame.pos.x == 956)
339 {
340 // Check for all 4 buttons
341 for (int i = 0; i < 4; i++)
342 {
343 // Check for collision between the mouse pointer and the option hitbox
344 if (CheckCollisionPointRec(Vector2(GetMousePosition()), options[i].hitbox))
345 {
346 drawOptionComponent(options, options[i].hoverEffect, options[i].hitbox.x, options[i].hitbox.y, index, i);
347 }
348 }
349 }
350}
351
355void drawOptionIndicators(City activeCity, Option options[4], PopUpAnimationFrame quizAnimationFrame, bool optionSelected,int index)
356{
357 if (optionSelected)
358 {
359 // Check for all 4 buttons
360 for (int i = 0; i < 4; i++)
361 {
362 // Draw indicators if the selected option was true
363 if (activeCity.trueAnswer == i + 1)
364 {
365 switch (i)
366 {
367 case 0:
368 drawOptionComponent(options, options[i].trueAnswerIndicator, quizAnimationFrame.pos.x + 77, quizAnimationFrame.pos.y + 802, index, i);
369 break;
370 case 1:
371 drawOptionComponent(options, options[i].trueAnswerIndicator, quizAnimationFrame.pos.x + 77, quizAnimationFrame.pos.y + 869, index, i);
372 break;
373 case 2:
374 drawOptionComponent(options, options[i].trueAnswerIndicator, quizAnimationFrame.pos.x + 78, quizAnimationFrame.pos.y + 937, index, i);
375 break;
376 case 3:
377 drawOptionComponent(options, options[i].trueAnswerIndicator, quizAnimationFrame.pos.x + 77, quizAnimationFrame.pos.y + 1005, index, i);
378 break;
379 }
380 }
381 // Draw indicators if the selected option was false
382 else
383 {
384 switch (i)
385 {
386 case 0:
387 drawOptionComponent(options, options[i].falseAnswerIndicator, quizAnimationFrame.pos.x + 77, quizAnimationFrame.pos.y + 802, index, i);
388 break;
389 case 1:
390 drawOptionComponent(options, options[i].falseAnswerIndicator, quizAnimationFrame.pos.x + 77, quizAnimationFrame.pos.y + 869, index, i);
391 break;
392 case 2:
393 drawOptionComponent(options, options[i].falseAnswerIndicator, quizAnimationFrame.pos.x + 78, quizAnimationFrame.pos.y + 937, index, i);
394 break;
395 case 3:
396 drawOptionComponent(options, options[i].falseAnswerIndicator, quizAnimationFrame.pos.x + 77, quizAnimationFrame.pos.y + 1004, index, i);
397 break;
398 }
399
400 }
401 }
402 }
403}
void manageWarningAnimation(Vector2 mousePoint, City cities[40], City activeCity, PopUpAnimationFrame *warningAnimationFramePtr, PopUpAnimationFrame popUpMenuFrame, Timer *warningTimerPtr, float *warningScreentimePtr, bool *wariningVisiblePtr, bool showPopUpMenu)
Manage warning animation.
Definition: animations.cpp:237
void drawQuizOptionsHover(Option options[4], PopUpAnimationFrame quizAnimationFrame, int index)
Draw quiz options hover effect.
Definition: animations.cpp:335
void drawOptionIndicators(City activeCity, Option options[4], PopUpAnimationFrame quizAnimationFrame, bool optionSelected, int index)
Draw option indicators to show if the selected option was true or false.
Definition: animations.cpp:355
void drawPopUpMenuHover(Rectangle confirmHitbox, Rectangle denyHitbox, Texture2D confirmHover, Texture2D denyHover, PopUpAnimationFrame *popUpAnimationFramePtr)
Draw popUp buttons hover effect.
Definition: animations.cpp:214
void drawPopUpAnimationBottom(PopUpAnimationFrame *componentPtr, float endY, bool showComponent)
Draw pop-up animation across its different states.
Definition: animations.cpp:97
void drawActiveCityAnimation(ActiveCityAnimationFrame *activeCityAnimationParts, City activeCity)
Draw active city animation.
Definition: animations.cpp:12
void drawPopUpAnimationSide(PopUpAnimationFrame *quizPtr, Texture2D texture, bool showQuiz)
Draw pop-up animation side.
Definition: animations.cpp:156
void drawOptionComponent(Option options[4], Texture2D texture, float x, float y, int index, int i)
Draw option components.
Definition: animations.cpp:287
#define frame6
Definition: animations.h:15
#define frame3
Definition: animations.h:12
#define frame4
Definition: animations.h:13
#define frame5
Definition: animations.h:14
#define frame2
Definition: animations.h:11
#define frame9
Definition: animations.h:18
#define frame8
Definition: animations.h:17
#define frame7
Definition: animations.h:16
#define frame10
Definition: animations.h:19
#define frame1
Define active city animation colors.
Definition: animations.h:10
#define RAYWHITE
Definition: raylib.h:174
RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint)
Definition: rtextures.c:3189
RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec)
Definition: rshapes.c:1599
RLAPI Vector2 GetMousePosition(void)
Definition: rcore.c:3761
@ MOUSE_BUTTON_LEFT
Definition: raylib.h:648
RLAPI bool IsMouseButtonPressed(int button)
Definition: rcore.c:3696
RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint)
Definition: rtextures.c:3183
RLAPI void DrawCircleV(Vector2 center, float radius, Color color)
Definition: rshapes.c:436
Define Active city animation frame struct.
Definition: animations.h:24
Initialise cities.
Definition: cityOperations.h:8
bool wasVisited
int trueAnswer
Rectangle hitbox
Vector2 coordinates
std::string name
Rectangle hitbox
Definition: quizLogic.h:8
Define Pop up animation frame.
Definition: animations.h:39
Texture2D texture
Definition: animations.h:42
float height
Definition: raylib.h:232
float x
Definition: raylib.h:229
float y
Definition: raylib.h:230
float width
Definition: raylib.h:231
Definition: timer.h:5
float x
Definition: physac.h:130
float y
Definition: physac.h:131
void StartTimer(Timer *timer, float lifetime)
Start or restart a timer with a specific lifetime.
Definition: timer.cpp:7
void UpdateTimer(Timer *timer)
Update a timer with the current frame time.
Definition: timer.cpp:18
bool TimerDone(Timer *timer)
Check if a timer is done.
Definition: timer.cpp:30