Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
cityOperations.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <string>
3#include "raylib.h"
4#include "cityOperations.h"
5
6// Initialise cities
8{
9 float hitboxWidth = 15, hitboxHeight = 20;
10 //---------------------------------------------------------------------------------------------------------------------------------------------------------------------//
11 // Categories: Name: Position: Rectangle Hitbox: Hitbox: VCI: TA: Texture File Path: //
12 cities[0] = { "Reykjavik", Vector2{185, 355}, Rectangle{185, 355, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Reykjavik.png" };
13 cities[1] = { "Oslo", Vector2{1240, 940}, Rectangle{1240, 940, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Oslo.png" };
14 cities[2] = { "Stockholm", Vector2{1540, 970}, Rectangle{1540, 970, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window Stockholm.png" };
15 cities[3] = { "Tallinn", Vector2{1800, 920}, Rectangle{1800, 920, hitboxWidth, hitboxHeight}, false, 2, "../resources/images/quizzes/Quiz window Tallinn.png" };
16 cities[4] = { "Riga", Vector2{1810, 1100}, Rectangle{1810, 1100, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Riga.png" };
17 cities[5] = { "Vilnius", Vector2{1890, 1270}, Rectangle{1890, 1270, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window Vilnius.png" };
18 cities[6] = { "Copenhagen", Vector2{1330, 1270}, Rectangle{1330, 1270, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Copenhagen.png" };
19 cities[7] = { "Edinburgh", Vector2{670, 1200}, Rectangle{670, 1200, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Edinburgh.png" };
20 cities[8] = { "Dublin", Vector2{470, 1360}, Rectangle{470, 1360, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Dublin.png" };
21 cities[9] = { "Hamburg", Vector2{1215, 1440}, Rectangle{1215, 1440, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Hamburg.png" };
22 cities[10] = { "Minsk", Vector2{2020, 1340}, Rectangle{2020, 1340, hitboxWidth, hitboxHeight}, false, 2, "../resources/images/quizzes/Quiz window Minsk.png" };
23 cities[11] = { "Warsaw", Vector2{1730, 1495}, Rectangle{1730, 1495, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Warsaw.png" };
24 cities[12] = { "Berlin", Vector2{1360, 1510}, Rectangle{1360, 1510, hitboxWidth, hitboxHeight}, false, 2, "../resources/images/quizzes/Quiz window Berlin.png" };
25 cities[13] = { "Amsterdam", Vector2{980, 1520}, Rectangle{980, 1520, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Amsterdam.png" };
26 cities[14] = { "London", Vector2{735, 1560}, Rectangle{735, 1560, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window London.png" };
27 cities[15] = { "Paris", Vector2{830, 1760}, Rectangle{830, 1760, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Paris.png" };
28 cities[16] = { "Brussels", Vector2{940, 1630}, Rectangle{940, 1630, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Brussels.png" };
29 cities[17] = { "Prague", Vector2{1415, 1715}, Rectangle{1415, 1715, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window Prague.png" };
30 cities[18] = { "Krakow", Vector2{1670, 1690}, Rectangle{1670, 1690, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Krakow.png" };
31 cities[19] = { "Budapest", Vector2{1690, 1890}, Rectangle{1690, 1890, hitboxWidth, hitboxHeight}, false, 2, "../resources/images/quizzes/Quiz window Budapest.png" };
32 cities[20] = { "Vienna", Vector2{1545, 1845}, Rectangle{1545, 1845, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Vienna.png" };
33 cities[21] = { "Munich", Vector2{1305, 1875}, Rectangle{1305, 1875, hitboxWidth, hitboxHeight}, false, 2, "../resources/images/quizzes/Quiz window Munich.png" };
34 cities[22] = { "Zagreb", Vector2{1525, 2055}, Rectangle{1525, 2055, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Zagreb.png" };
35 cities[23] = { "Belgrade", Vector2{1790, 2080}, Rectangle{1790, 2080, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Belgrade.png" };
36 cities[24] = { "Bucharest", Vector2{2095, 2050}, Rectangle{2095, 2050, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window Bucharest.png" };
37 cities[25] = { "Nessebar", Vector2{2210, 2165}, Rectangle{2210, 2165, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window Nessebar.png" };
38 cities[26] = { "Sofia", Vector2{1980, 2230}, Rectangle{1980, 2230, hitboxWidth, hitboxHeight}, false, 3, "../resources/images/quizzes/Quiz window Sofia.png" };
39 cities[27] = { "Sarajevo", Vector2{1680, 2155}, Rectangle{1680, 2155, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window Sarajevo.png" };
40 cities[28] = { "Florence", Vector2{1290, 2205}, Rectangle{1290, 2205, hitboxWidth, hitboxHeight}, false, 2, "../resources/images/quizzes/Quiz window Florence.png" };
41 cities[29] = { "Marseille", Vector2{960, 2230}, Rectangle{960, 2230, hitboxWidth, hitboxHeight}, false, 2, "../resources/images/quizzes/Quiz window Marseille.png" };
42 cities[30] = { "Rome", Vector2{1360, 2345}, Rectangle{1360, 2345, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Rome.png" };
43 cities[31] = { "Lisbon", Vector2{50, 2445}, Rectangle{50, 2445, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window Lisbon.png" };
44 cities[32] = { "Madrid", Vector2{405, 2410}, Rectangle{405, 2410, hitboxWidth, hitboxHeight}, false, 2, "../resources/images/quizzes/Quiz window Madrid.png" };
45 cities[33] = { "Barcelona", Vector2{765, 2355}, Rectangle{765, 2355, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Barcelona.png" };
46 cities[34] = { "Cagliari", Vector2{1165, 2545}, Rectangle{1165, 2545, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Cagliari.png" };
47 cities[35] = { "Palermo", Vector2{1415, 2635}, Rectangle{1415, 2635, hitboxWidth, hitboxHeight}, false, 2, "../resources/images/quizzes/Quiz window Palermo.png" };
48 cities[36] = { "Helsinki", Vector2{1765, 865}, Rectangle{1765, 865, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Helsinki.png" };
49 cities[37] = { "Ioannina", Vector2{1870, 2465}, Rectangle{1870, 2465, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window Ioannina.png" };
50 cities[38] = { "Athens", Vector2{2065, 2575}, Rectangle{2065, 2575, hitboxWidth, hitboxHeight}, false, 4, "../resources/images/quizzes/Quiz window Athens.png" };
51 cities[39] = { "Istanbul", Vector2{2315, 2275}, Rectangle{2315, 2275, hitboxWidth, hitboxHeight}, false, 1, "../resources/images/quizzes/Quiz window Istanbul.png" };
52 //---------------------------------------------------------------------------------------------------------------------------------------------------------------------//
53
54 // Return intialised array
55 return cities;
56}
57
58// Draw city marks on the map
59void drawCityNames(City* cities, int citiesCounter, Font comfortaaRegular)
60{
61 for (int i = 0; i < citiesCounter; i++)
62 {
63 // Draw city names
64 DrawTextEx(comfortaaRegular, cities[i].name.c_str(), Vector2{ cities[i].coordinates.x + 7,cities[i].coordinates.y + 7 }, (float)comfortaaRegular.baseSize, 1, WHITE);
65 }
66}
67
68// Draw city markers based of distance from active city
69void drawCityMarkers(City* cities, City activeCity, Texture2D markers[3], int citiesCounter)
70{
71 double distance = 0;
72 for (int i = 0; i < citiesCounter; i++)
73 {
74 // Calculate distance between a city from the array and the active city
75 distance = sqrt(pow(activeCity.coordinates.x - cities[i].coordinates.x, 2) + pow(activeCity.coordinates.y - cities[i].coordinates.y, 2));
76
77 // Check for first range for distance (Close)
78 if (distance >= 0 && distance <= 350)
79 {
80 // Draw city markers for cities that are close to the active city
81 DrawTextureV(markers[0], Vector2{ cities[i].hitbox.x - float(markers[0].width / 2), cities[i].hitbox.y - float(markers[0].height / 2) }, RAYWHITE);
82 }
83 // Check for second range for distance (Near)
84 else if (distance >= 351 && distance <= 800)
85 {
86 // Draw city markers for cities that are near the active city
87 DrawTextureV(markers[1], Vector2{ cities[i].hitbox.x - float(markers[1].width / 2), cities[i].hitbox.y - float(markers[1].height / 2) }, RAYWHITE);
88 }
89 // Check for second range for distance (Far away)
90 else if (distance > 800)
91 {
92 // Draw city markers for cities that are far away from the active city
93 DrawTextureV(markers[2], Vector2{ cities[i].hitbox.x - float(markers[2].width / 2), cities[i].hitbox.y - float(markers[2].height / 2) }, RAYWHITE);
94 }
95 }
96}
97
98// Update city travel cost and bonus
99void updateCityTravelCostAndBonus(City* cities, City activeCity, int citiesCounter)
100{
101 double distance = 0;
102 for (int i = 0; i < citiesCounter; i++)
103 {
104 // Calculate distance between a city from the array and the active city
105 distance = sqrt(pow(activeCity.coordinates.x - cities[i].coordinates.x, 2) + pow(activeCity.coordinates.y - cities[i].coordinates.y, 2));
106
107 // Check for first range for distance (Close)
108 if (distance >= 0 && distance <= 350)
109 {
110 // Update travel cost and bonus for close cities
111 cities[i].travelCost = 1;
112 cities[i].bonus = 0;
113 }
114 // Check for second range for distance (Near)
115 else if (distance >= 351 && distance <= 800)
116 {
117 // Update travel cost and bonus for near cities
118 cities[i].travelCost = 2;
119 cities[i].bonus = 50;
120 }
121 // Check for second range for distance (Far away)
122 else if (distance > 800)
123 {
124 // Update travel cost and bonus for far away cities
125 cities[i].travelCost = 3;
126 cities[i].bonus = 100;
127 }
128 }
129}
City * intialiseCitiesArray(City cities[40])
Initialise cities.
void updateCityTravelCostAndBonus(City *cities, City activeCity, int citiesCounter)
Update city travel cost and bonus.
void drawCityMarkers(City *cities, City activeCity, Texture2D markers[3], int citiesCounter)
Draw city markers based of distance from active city.
void drawCityNames(City *cities, int citiesCounter, Font comfortaaRegular)
Draw city marks on the map.
#define RAYWHITE
Definition: raylib.h:174
RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint)
Definition: rtextures.c:3189
#define WHITE
Definition: raylib.h:170
RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
Definition: rtext.c:1024
Initialise cities.
Definition: cityOperations.h:8
int travelCost
int bonus
Rectangle hitbox
Vector2 coordinates
Definition: raylib.h:289
int baseSize
Definition: raylib.h:290
float x
Definition: raylib.h:229
float y
Definition: raylib.h:230
float x
Definition: physac.h:130
float y
Definition: physac.h:131