-
Notifications
You must be signed in to change notification settings - Fork 0
/
levelsCode.cs
209 lines (162 loc) · 6 KB
/
levelsCode.cs
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class levelsCode : MonoBehaviour
{
//Level stats
public int levelNumber = 0;
public float waveSpeed;
private float baseWaveSpeed;
public float waveAcc;
private int waveIndex = 0;
public Text waveIndexText;
//shop stats
public GameObject[] shop;
public int shopLength;
public int shopIndex;
private bool canOpenShop = true;
private int lastShopIndex;
public float scale;
//enemy stats
public GameObject[] enemies;
public int enemiesLength;
public int baseEnemiesLength;
public int enemiesIndex;
public int[] waveEnemyAmount;
public int[] waveEnemyTypes;
public GameObject[] bossEnemies;
public int[] bossWaves;
//player stats
//health
public float maxHealth = 5;
public Text maxHealthText;
public float health;
public float regen = 0;
public Text regenText;
//economy
public int money = 0;
public Text moneyText;
public float coinsPer20Seconds;
public Text coinsPer20SecondsText;
public int moneyPerRound;
public Text moneyPerRoundText;
public int gold = 0;
public int gems = 0;
public int emeralds = 0;
//Private variables
private bool canGiveMoney = true;
private bool canHeal = true;
private int spawned = 0;
private bool canSpawn = true;
private int numberOfWaves;
private bool canContinueWave = true;
public bool canStartWave = false;
public int waveSeparationTime;
private bool bossSpawned = false;
private int bossWaveIndex = 1;
private GameObject lastEnemy;
void Start()
{
maxHealth = float.Parse(maxHealthText.text);
health = maxHealth;
waveIndexText.text = "1";
baseWaveSpeed = waveSpeed;
enemiesLength = enemies.Length;
baseEnemiesLength = enemiesLength;
//red = tank, blue = mage, yellow = healer, orange = bomb, green = speed, gray = shield, black = camo, brown = normal, purple = boss.
shopLength = shop.Length;
numberOfWaves = waveEnemyAmount.Length;
}
void Update() {
coinsPer20Seconds = float.Parse(coinsPer20SecondsText.text);
moneyPerRound = int.Parse(moneyPerRoundText.text);
maxHealth = float.Parse(maxHealthText.text);
regen = float.Parse(regenText.text) / 100;
moneyText.text = money + "";
if (canOpenShop) {
shop[shopIndex].transform.position = new Vector3(565f + 960, -344f+540, 0f);
canOpenShop = false;
lastShopIndex = shopIndex;
}
if (canOpenShop == false) {
Vector3 pos = shop[shopIndex].transform.position;
pos.y += Input.mouseScrollDelta.y * -1 * scale;
shop[shopIndex].transform.position = pos;
}
if (shopIndex == 0) {
shop[lastShopIndex].transform.position = new Vector3(1321f + 960, -344f+540, 0f);
canOpenShop = true;
}
if (canContinueWave == true && spawned < waveEnemyAmount[waveIndex]) {
StartCoroutine(Spawnings());
Debug.Log(spawned);
} else if (canContinueWave == true && spawned >= waveEnemyAmount[waveIndex] && bossWaves[bossWaveIndex - 1] == waveIndex + 1) {
if (bossSpawned == false) {
Debug.Log("boss spawned");
bossEnemies[bossWaveIndex-1].GetComponent<EnemyCoded>().Spawn();
bossSpawned = true;
canContinueWave = false;
}
} else if (bossSpawned == true && bossEnemies[bossWaveIndex - 1].activeInHierarchy == false) {
Debug.Log("boss fight finished");
canStartWave = true;
bossWaveIndex++;
if (canStartWave && spawned >= waveEnemyAmount[waveIndex]) {
StartCoroutine(NewWave());
}
} else if (spawned >= waveEnemyAmount[waveIndex] && canContinueWave == true) {
Debug.Log("wave without boss finished");
canStartWave = true;
canContinueWave = false;
if (canStartWave && spawned >= waveEnemyAmount[waveIndex]) {
StartCoroutine(NewWave());
}
}
StartCoroutine(CoinsPer20Seconds());
StartCoroutine(Regen());
}
private IEnumerator Spawnings() {
if (canSpawn) {
enemies[enemiesIndex].GetComponent<EnemyCoded>().Spawn();
spawned++;
while (enemies[enemiesIndex].activeInHierarchy == true) {
enemiesIndex = Random.Range(0, waveEnemyTypes[waveIndex]);
}
canSpawn = false;
yield return new WaitForSeconds(1 / waveSpeed);
canSpawn = true;
waveSpeed = waveSpeed + waveAcc;
}
}
private IEnumerator CoinsPer20Seconds() {
if (canGiveMoney && coinsPer20Seconds != 0) {
money++;
canGiveMoney = false;
yield return new WaitForSeconds(20 / (coinsPer20Seconds));
canGiveMoney = true;
}
}
private IEnumerator Regen() {
if (canHeal && regen != 0 && health < maxHealth) {
health = health + regen;
canHeal = false;
yield return new WaitForSeconds(1);
canHeal = true;
}
}
private IEnumerator NewWave() {
bossSpawned = false;
spawned = 0;
canStartWave = false;
canContinueWave = false;
Debug.Log("Wave Finished");
yield return new WaitForSeconds(waveSeparationTime);
Debug.Log("newWave");
waveIndex++;
waveSpeed = baseWaveSpeed;
waveIndexText.text = waveIndex + 1 + "";
money = money + moneyPerRound;
canContinueWave = true;
}
}