@@ -5,10 +5,10 @@ Board::Board(Camera* camera, ParticleSystem* particleSystem, Graph* graph, vecto
5
5
{
6
6
spawnTimer = glfwGetTime () - spawnDelay;
7
7
srand (time (NULL ));
8
- createTower (0 ,(int )rand () % 3 , 0 , glm::vec3 (-4.0 , 0.5 , 0 ));
9
- createTower (0 ,(int )rand () % 3 , 0 , glm::vec3 (-2.5 , 0.5 , 0 ));
10
- createTower (1 ,(int )rand () % 3 , 1 , glm::vec3 (4.0 , 0.5 , 0 ));
11
- createTower (1 ,(int )rand () % 3 , 1 , glm::vec3 (2.5 , 0.5 , 0 ));
8
+ createTower (1 ,(int )rand () % 3 , 0 , glm::vec3 (-4.0 , 0.5 , 0 ));
9
+ createTower (1 ,(int )rand () % 3 , 0 , glm::vec3 (-2.5 , 0.5 , 0 ));
10
+ createTower (0 ,(int )rand () % 3 , 1 , glm::vec3 (4.0 , 0.5 , 0 ));
11
+ createTower (0 ,(int )rand () % 3 , 1 , glm::vec3 (2.5 , 0.5 , 0 ));
12
12
}
13
13
14
14
const double Board::heights[] = {-0.32 , -0.58 , -0.84 };
@@ -34,35 +34,70 @@ void Board::update(double deltaTime)
34
34
castles.at (i)->update (deltaTime, (2 .0f * mousePosition - cameraPosition), castles.at ((i) ? 0 : 1 ));
35
35
}
36
36
37
+ // adds funds every 5 seconds
38
+ if ((glfwGetTime () - fundsTimer) > fundsDelay) {
39
+ fundsTimer = glfwGetTime ();
40
+ for (int i = 0 ; i < castles.size (); i++)
41
+ {
42
+ castles.at (i)->addFunds (5 );
43
+ }
44
+ }
45
+
46
+ #pragma region Enemy Spawning
37
47
if ((glfwGetTime () - spawnTimer) > spawnDelay)
38
48
{
39
- spawnTimer = glfwGetTime ();
40
- createUnit (0 ,(int )rand () % 4 , 0 , glm::vec3 (-4.92 , heights[(int )rand () % 3 ], 0 ));
49
+ switch ((int )rand () % 4 ) {
50
+ case 0 :
51
+ if (castles.at (0 )->spendFunds (u1Cost)) {
52
+ createUnit (0 , 0 , 0 , glm::vec3 (4.92 , heights[(int )rand () % 3 ], 0 ));
53
+ spawnTimer = glfwGetTime ();
54
+ }
55
+ break ;
56
+ case 1 :
57
+ if (castles.at (0 )->spendFunds (u2Cost)) {
58
+ createUnit (0 , 1 , 0 , glm::vec3 (4.92 , heights[(int )rand () % 3 ], 0 ));
59
+ spawnTimer = glfwGetTime ();
60
+ }
61
+ break ;
62
+ case 2 :
63
+ if (castles.at (0 )->spendFunds (u3Cost)) {
64
+ createUnit (0 , 2 , 0 , glm::vec3 (4.92 , heights[(int )rand () % 3 ], 0 ));
65
+ spawnTimer = glfwGetTime ();
66
+ }
67
+ break ;
68
+ case 3 :
69
+ if (castles.at (0 )->spendFunds (u4Cost)) {
70
+ createUnit (0 , 3 , 0 , glm::vec3 (4.92 , heights[(int )rand () % 3 ], 0 ));
71
+ spawnTimer = glfwGetTime ();
72
+ }
73
+ break ;
74
+ }
41
75
}
76
+ #pragma endregion
42
77
43
78
#pragma region Key Control
44
79
if (((glfwGetTime () - createTimer)) > createDelay) {
45
80
if (glfwGetKey (Window::getWindow (), GLFW_KEY_1) == GLFW_PRESS) {
46
81
if (castles.at (1 )->spendFunds (u1Cost)) {
47
- createUnit (1 , 0 , 1 , glm::vec3 (4.92 , heights[(int )rand () % 3 ], 0 ));
82
+ createUnit (1 , 0 , 1 , glm::vec3 (- 4.92 , heights[(int )rand () % 3 ], 0 ));
48
83
createTimer = glfwGetTime ();
49
84
}
50
85
}
51
86
else if (glfwGetKey (Window::getWindow (), GLFW_KEY_2) == GLFW_PRESS) {
52
87
if (castles.at (1 )->spendFunds (u2Cost)) {
53
- createUnit (1 , 1 , 1 , glm::vec3 (4.92 , heights[(int )rand () % 3 ], 0 ));
88
+ createUnit (1 , 1 , 1 , glm::vec3 (- 4.92 , heights[(int )rand () % 3 ], 0 ));
54
89
createTimer = glfwGetTime ();
55
90
}
56
91
}
57
92
else if (glfwGetKey (Window::getWindow (), GLFW_KEY_3) == GLFW_PRESS) {
58
93
if (castles.at (1 )->spendFunds (u3Cost)) {
59
- createUnit (1 , 2 , 1 , glm::vec3 (4.92 , heights[(int )rand () % 3 ], 0 ));
94
+ createUnit (1 , 2 , 1 , glm::vec3 (- 4.92 , heights[(int )rand () % 3 ], 0 ));
60
95
createTimer = glfwGetTime ();
61
96
}
62
97
}
63
98
else if (glfwGetKey (Window::getWindow (), GLFW_KEY_4) == GLFW_PRESS) {
64
99
if (castles.at (1 )->spendFunds (u4Cost)) {
65
- createUnit (1 , 3 , 1 , glm::vec3 (4.92 , heights[(int )rand () % 3 ], 0 ));
100
+ createUnit (1 , 3 , 1 , glm::vec3 (- 4.92 , heights[(int )rand () % 3 ], 0 ));
66
101
createTimer = glfwGetTime ();
67
102
}
68
103
}
@@ -117,8 +152,8 @@ void Board::createUnit(int castleNumber, int type, bool playerControlled, glm::v
117
152
playerControlled,
118
153
movementSpeed,
119
154
graph,
120
- glm::vec3 ((playerControlled) ? -0.1 : 0.1 , 0.15 , 1 ),
121
- (playerControlled) ? glm::vec2 (-5.88 , -0.32 ) : glm::vec2 (5.88 , -0.32 ),
155
+ glm::vec3 ((! playerControlled) ? -0.1 : 0.1 , 0.15 , 1 ),
156
+ (! playerControlled) ? glm::vec2 (-5.88 , -0.32 ) : glm::vec2 (5.88 , -0.32 ),
122
157
position,
123
158
castle->getUnitTextures ().at (type),
124
159
castle->getNumElem ()));
0 commit comments