-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSpawner.cpp
More file actions
112 lines (99 loc) · 2.33 KB
/
Spawner.cpp
File metadata and controls
112 lines (99 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Spawner.h"
Spawner::Spawner()
{
}
Spawner::~Spawner()
{
}
void Spawner::tick()
{
if (mode == NO_MODE)
{
if (glfwGetKey(window, GLFW_KEY_N)) mode = Normal;
if (glfwGetKey(window, GLFW_KEY_R)) mode = CTRush;
if (glfwGetKey(window, GLFW_KEY_Z)) mode = Zombie;
}
else if (time++ % 250 == 0){
wave++;
switch (mode)
{
case Normal:
wave_normal();
break;
case CTRush:
wave_CTRush();
break;
case Zombie:
wave_zombie();
break;
default:
break;
}
}
}
void Spawner::wave_normal()
{
int remainingCount = wave;
if (wave % 10 == 0) //BOSS WAVE!
{
for (int i = 0; i < wave / 2; i++) //EAT CARRIERS!
{
((CarrierHolder*)(holderArray[CARRIER]))->AddCarrier();
}
for (int i = 0; i < wave / 2; i++) //And these, too,
{
((LineTripperHolder*)(holderArray[LINETRIPPER]))->AddLineTripper();
}
remainingCount = 0; //Nothing else needs to happen.
}
if (wave % 10 == 1 && wave > 10) remainingCount = 0; //Reward for stopping a boss.
if (wave >= 3){
int motherShipCount = remainingCount > 0 ? (rand() % (remainingCount / 2)) : 0;
for (int i = 0; i < motherShipCount; i++)
{
((MothershipHolder*)(holderArray[MOTHERSHIP]))->addMothership();
}
remainingCount -= motherShipCount * 2;
if (remainingCount > 0)
{
int lineTripperCount = (rand() % remainingCount / 3);
for (int i = 0; i < lineTripperCount; i++)
{
((LineTripperHolder*)(holderArray[LINETRIPPER]))->AddLineTripper();
}
remainingCount -= lineTripperCount;
}
if (remainingCount > 0)
{
int carrierCount = (rand() % remainingCount / 3);
for (int i = 0; i < carrierCount; i++)
{
((CarrierHolder*)(holderArray[CARRIER]))->AddCarrier();
}
remainingCount -= carrierCount * 2;
}
}
for (int i = 0; i < remainingCount; i++){
((ZombieHolder*)(holderArray[ZOMBIE]))->AddZombie();
}
}
void Spawner::wave_CTRush()
{
for (int i = 0; i < wave; i++)
{
((MothershipHolder*)(holderArray[MOTHERSHIP]))->addMothership();
((CarrierHolder*)(holderArray[CARRIER]))->AddCarrier();
}
}
void Spawner::wave_zombie()
{
for (int i = 0; i < wave * 3; i++)
{
((ZombieHolder*)(holderArray[ZOMBIE]))->AddZombie();
if (rand() % 10 == 0)
{
((LineTripperHolder*)(holderArray[LINETRIPPER]))->AddLineTripper();
i--;
}
}
}