Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
travelLogic.cpp
Go to the documentation of this file.
1#include <vector>
2#include "raylib.h"
3#include "cityOperations.h"
4#include "travelLogic.h"
5#include "animations.h"
6#include "manageActiveText.h"
7
11void travelToNextCity(Vector2 mousePoint, City* cities, City activeCity, City* tempCity, bool* searchingNextCity, bool* showPopUpMenu, int citiesCounter, int* indexPtr)
12{
13 // Check if travel is allowed
14 if (searchingNextCity)
15 {
16 for (int i = 0; i < citiesCounter; i++)
17 {
18 // Check for collision between a city's marker and the mouse pointer
19 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 }))
20 {
21 // Check if selected city is available for travel
22 if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && cities[i].name != activeCity.name && cities[i].wasVisited == false)
23 {
24 // Store the index of the selected city
25 *indexPtr = i;
26
27 // Update the temporary city's value
28 *tempCity = cities[i];
29
30 // Temporary restrict travel
31 *searchingNextCity = false;
32
33 // Extent pop-up
34 *showPopUpMenu = true;
35 }
36 }
37 }
38 }
39}
40
44void handlePopUpInput(City* cities, City* activeCity, City* tempCity, PopUpAnimationFrame popUpFrame, Rectangle confirmHitbox, Rectangle denyHitbox, std::vector<LinePoints>* conLinesPtr, bool* searchingNextCity, bool* showPopUpMenu, bool* nextCityChosenPtr, int* indexPtr, int* travelPointsPtr, int* bonusPtr)
45{
46 // Check if confirm was clicked
48 {
49 // Retract the pop-up
50 *showPopUpMenu = false;
51
52 // Allow travel to other selected cities
53 *searchingNextCity = true;
54
55 // Restrict further access to selected city
56 cities[*indexPtr].wasVisited = true;
57
58 // Check if next city is choosen(helps in managing the quizzes)
59 *nextCityChosenPtr = true;
60
61 // Check and avoid line dublication
62 if (activeCity->coordinates.x > 0 && activeCity->coordinates.y > 0 && tempCity->coordinates.x > 0 && tempCity->coordinates.y > 0)
63 {
64 // Add next set of start and end line points
65 conLinesPtr->push_back({ activeCity->coordinates, tempCity->coordinates });
66
67 // Update travel points count
68 *travelPointsPtr -= tempCity->travelCost;
69
70 // Assign bonus points
71 *bonusPtr = tempCity->bonus;
72
73 // Upadate the active city
74 *activeCity = *tempCity;
75
76 // Reset the temporary city
77 *tempCity = {};
78 }
79 }
80 // Check if deny was clicked
81 else if (showPopUpMenu && CheckCollisionPointRec(Vector2(GetMousePosition()), denyHitbox) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
82 {
83 // Retract the pop-up
84 *showPopUpMenu = false;
85
86 // Allow travel to other selected cities
87 *searchingNextCity = false;
88
89 // Check if next city is choosen(helps in managing the quizzes)
90 *nextCityChosenPtr = false;
91
92 // Reset the temporary city
93 *tempCity = {};
94 }
95}
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
Initialise cities.
Definition: cityOperations.h:8
int travelCost
int bonus
bool wasVisited
Rectangle hitbox
Vector2 coordinates
std::string name
Define Pop up animation frame.
Definition: animations.h:39
float height
Definition: raylib.h:232
float x
Definition: raylib.h:229
float width
Definition: raylib.h:231
float x
Definition: physac.h:130
float y
Definition: physac.h:131
void travelToNextCity(Vector2 mousePoint, City *cities, City activeCity, City *tempCity, bool *searchingNextCity, bool *showPopUpMenu, int citiesCounter, int *indexPtr)
Travel to next selected city (if possible).
Definition: travelLogic.cpp:11
void handlePopUpInput(City *cities, City *activeCity, City *tempCity, PopUpAnimationFrame popUpFrame, Rectangle confirmHitbox, Rectangle denyHitbox, std::vector< LinePoints > *conLinesPtr, bool *searchingNextCity, bool *showPopUpMenu, bool *nextCityChosenPtr, int *indexPtr, int *travelPointsPtr, int *bonusPtr)
Handle mouse input for the pop-up.
Definition: travelLogic.cpp:44