Skip to content

Commit 8e3cb9d

Browse files
author
eros.dipede
committed
Switch player side, updated controls, add to gui
1 parent 3c46f86 commit 8e3cb9d

22 files changed

+159
-82
lines changed

TextureDemo/TextureDemo/Board.cpp

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Board::Board(Camera* camera, ParticleSystem* particleSystem, Graph* graph, vecto
55
{
66
spawnTimer = glfwGetTime() - spawnDelay;
77
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));
1212
}
1313

1414
const double Board::heights[] = {-0.32, -0.58, -0.84 };
@@ -34,35 +34,70 @@ void Board::update(double deltaTime)
3434
castles.at(i)->update(deltaTime, (2.0f * mousePosition - cameraPosition), castles.at((i) ? 0 : 1));
3535
}
3636

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
3747
if ((glfwGetTime() - spawnTimer) > spawnDelay)
3848
{
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+
}
4175
}
76+
#pragma endregion
4277

4378
#pragma region Key Control
4479
if (((glfwGetTime() - createTimer)) > createDelay) {
4580
if (glfwGetKey(Window::getWindow(), GLFW_KEY_1) == GLFW_PRESS) {
4681
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));
4883
createTimer = glfwGetTime();
4984
}
5085
}
5186
else if (glfwGetKey(Window::getWindow(), GLFW_KEY_2) == GLFW_PRESS) {
5287
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));
5489
createTimer = glfwGetTime();
5590
}
5691
}
5792
else if (glfwGetKey(Window::getWindow(), GLFW_KEY_3) == GLFW_PRESS) {
5893
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));
6095
createTimer = glfwGetTime();
6196
}
6297
}
6398
else if (glfwGetKey(Window::getWindow(), GLFW_KEY_4) == GLFW_PRESS) {
6499
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));
66101
createTimer = glfwGetTime();
67102
}
68103
}
@@ -117,8 +152,8 @@ void Board::createUnit(int castleNumber, int type, bool playerControlled, glm::v
117152
playerControlled,
118153
movementSpeed,
119154
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),
122157
position,
123158
castle->getUnitTextures().at(type),
124159
castle->getNumElem()));

TextureDemo/TextureDemo/Board.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ class Board
3434
const static double heights[];
3535
float spawnDelay = 20,
3636
spawnTimer = 0,
37+
fundsDelay = 5,
38+
fundsTimer = 0,
3739
u1Cost = 25,
38-
u2Cost = 25,
39-
u3Cost = 25,
40-
u4Cost = 25,
40+
u2Cost = 10,
41+
u3Cost = 100,
42+
u4Cost = 50,
4143
createTimer = 0,
42-
createDelay = 1;
44+
createDelay = 0.5;
4345
};
4446

TextureDemo/TextureDemo/Camera.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ void Camera::update(double deltaTime)
4747
shader.setUniformMat4("viewMatrix", viewMatrix);
4848

4949
//zooms camera in and out
50-
if (glfwGetKey(Window::getWindow(), GLFW_KEY_Z) == GLFW_PRESS) zoomCamera(-zoomSpeed);
51-
else if (glfwGetKey(Window::getWindow(), GLFW_KEY_X) == GLFW_PRESS) zoomCamera(zoomSpeed);
50+
if (glfwGetKey(Window::getWindow(), GLFW_KEY_Q) == GLFW_PRESS) zoomCamera(-zoomSpeed);
51+
else if (glfwGetKey(Window::getWindow(), GLFW_KEY_E) == GLFW_PRESS) zoomCamera(zoomSpeed);
5252

5353
//resets zoom scale
5454
if (glfwGetKey(Window::getWindow(), GLFW_KEY_R) == GLFW_PRESS) zoom = 0.5f;

TextureDemo/TextureDemo/Castle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void Castle::update(double deltaTime, glm::vec2 mousePosition, Castle* otherCast
6969
for (int i = 0; i < units.size(); i++)
7070
{
7171
Unit* unit = units.at(i);
72-
unit->update(deltaTime, otherCastles->getUnits());
72+
unit->update(deltaTime, otherCastles);
7373
if (unit->getHealth() <= 0)
7474
{
7575
unit = NULL;

TextureDemo/TextureDemo/Castle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class Castle :
2323
void update(double deltaTime,glm::vec2 mousePosition, Castle* otherCastles);
2424
//spend funds, return if funds were spent or not
2525
bool spendFunds(double funds);
26+
//increase funds
2627
inline void addFunds(double funds) { this->funds += funds; }
28+
//takes damage
29+
inline void takeDamage(double dmg) { health -= dmg; }
2730
//shooting functions
2831
void shoot(glm::vec3 target, int damage);
2932
void removeProjectile(int index);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)