-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemyWaveController.cs
172 lines (139 loc) · 6.91 KB
/
EnemyWaveController.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
using UnityEngine;
public class EnemyWaveController : MonoBehaviour
{
public int waveNumber;
int numberOfEnemies;
public int lastNumberOfEnemies;
public float startRadius;
public float increaseRate;
public float increaseSpeed;
Vector2 enemyPosition;
public GameObject enemyPrefab;
public GameObject redEnemyPrefab;
public static int enemiesKilled;
public static int highScore;
public GameObject player;
public GameObject crushParticles;
public GameObject circleBackground;
float newCircleBackgrounSize;
public bool sizeIncreased = false;
public GameObject[] redEnemies;
public float angle;
public GameObject enlargePowerupPrefab;
public GameObject snowPowerupPrefab;
public int maximumNumberOfEnemies;
public EnemyCreaterInCircle circleArea;
// Start is called before the first frame update
void Start()
{
highScore = 0;
waveNumber = 1;
enemiesKilled = 0;
newCircleBackgrounSize = 1;
maximumNumberOfEnemies = 500;
circleArea.radius = startRadius;
circleArea.numberOfEnemies = lastNumberOfEnemies;
circleArea.circleAreaPosition = new Vector2(0, 1);
circleArea.CreatePositions();
numberOfEnemies = lastNumberOfEnemies;
for (int index = 0; index < circleArea.numberOfEnemies; index++)
{
enemyPosition = circleArea.enemyPositions[index];
GameObject enemy = (GameObject)Instantiate(enemyPrefab, enemyPosition, Quaternion.Euler(0, 0, Random.Range(0, 120)), gameObject.transform);
enemy.GetComponent<Enemy>().circleAreaPosition = circleArea.circleAreaPosition;
enemy.GetComponent<Enemy>().radius = circleArea.radius;
}
redEnemies = new GameObject[waveNumber];
angle = Random.Range(0f, 1f) * Mathf.PI * 2;
GameObject redEnemy = (GameObject)Instantiate(redEnemyPrefab, new Vector2(Mathf.Cos(angle) * (circleArea.radius + Random.Range(5, 10)), Mathf.Sin(angle) * (circleArea.radius + Random.Range(5, 10) )), Quaternion.Euler(0, 0, Random.Range(0, 120)) );
redEnemies[0] = redEnemy;
PlayerPrefs.SetInt("EnlargePowerupExists", 0);
PlayerPrefs.SetInt("SnowPowerupExists", 0);
}
private void Update()
{
if (numberOfEnemies == enemiesKilled)
{
if(!sizeIncreased)
{
for (int i = 0; i < redEnemies.Length; i++)
Destroy(redEnemies[i]);
newCircleBackgrounSize += increaseRate;
if (PlayerPrefs.GetInt("SoundEnabled", 1) == 1)
FindObjectOfType<AudioManager>().PlayWithPitch("LevelWonSound" , 1.5f);
sizeIncreased = true;
}
IncreaseSize();
}
}
public void IncreaseSize()
{
if (circleBackground.transform.localScale.x < newCircleBackgrounSize)
{
circleBackground.transform.localScale += new Vector3(Time.deltaTime * increaseSpeed, Time.deltaTime * increaseSpeed, 0);
}
else
{
waveNumber += 1;
circleArea.radius = startRadius * newCircleBackgrounSize;
if (lastNumberOfEnemies < maximumNumberOfEnemies)
circleArea.numberOfEnemies = (int)(lastNumberOfEnemies * 1.45f);
else
circleArea.numberOfEnemies = maximumNumberOfEnemies;
lastNumberOfEnemies = circleArea.numberOfEnemies;
circleArea.circleAreaPosition = new Vector2(0, 1);
circleArea.CreatePositions();
numberOfEnemies = lastNumberOfEnemies;
for (int index = 0; index < circleArea.numberOfEnemies; index++)
{
enemyPosition = circleArea.enemyPositions[index];
GameObject enemy = (GameObject)Instantiate(enemyPrefab, enemyPosition, Quaternion.Euler(0, 0, Random.Range(0, 120)), gameObject.transform);
enemy.GetComponent<Enemy>().circleAreaPosition = circleArea.circleAreaPosition;
enemy.GetComponent<Enemy>().radius = circleArea.radius;
}
enemiesKilled = 0;
sizeIncreased = false;
redEnemies = new GameObject[waveNumber];
for( int i = 0; i < waveNumber; i++)
{
angle = Random.Range(0f, 1f) * Mathf.PI * 2;
GameObject redEnemy = (GameObject)Instantiate(redEnemyPrefab, new Vector2( Mathf.Cos(angle) * (circleArea.radius + Random.Range( 5, 10)) , Mathf.Sin(angle) * (circleArea.radius + Random.Range(5, 10) ) ), Quaternion.identity);
redEnemy.GetComponent<EnemyRed>().speed = Random.Range( 2f, waveNumber / 2f + 4f);
redEnemy.GetComponent<EnemyRed>().rotationSpeed = Random.Range(20, 80);
redEnemies[i] = redEnemy;
}
if( Random.Range(0, 10) < (8 - PlayerPrefs.GetInt("circleSize", 10) / 100) && PlayerPrefs.GetInt( "EnlargePowerupExists" , 0) == 0)
{
Instantiate(enlargePowerupPrefab, circleArea.enemyPositions[0] + Vector2.up * 1.5f, Quaternion.Euler(0, 0, Random.Range(0, 120)), gameObject.transform);
}
if (Random.Range(0, 10) < 4 - waveNumber / 4f && PlayerPrefs.GetInt("SnowPowerupExists", 0) == 0)
{
Instantiate(snowPowerupPrefab, enemyPosition + Vector2.up * 1.5f, Quaternion.Euler(0, 0, Random.Range(0, 120)), gameObject.transform);
}
}
}
public void ContinueMainLevel()
{
circleArea.numberOfEnemies = enemiesKilled;
circleArea.CreatePositions();
for (int index = 0; index < enemiesKilled; index++)
{
enemyPosition = circleArea.enemyPositions[index];
GameObject enemy = (GameObject)Instantiate(enemyPrefab, enemyPosition, Quaternion.Euler(0, 0, Random.Range(0, 120)), gameObject.transform);
enemy.GetComponent<Enemy>().circleAreaPosition = circleArea.circleAreaPosition;
enemy.GetComponent<Enemy>().radius = circleArea.radius;
}
for (int i = 0; i < redEnemies.Length; i++)
Destroy(redEnemies[i]);
redEnemies = new GameObject[waveNumber];
for (int i = 0; i < waveNumber; i++)
{
angle = Random.Range(0f, 1f) * Mathf.PI * 2;
GameObject redEnemy = (GameObject)Instantiate(redEnemyPrefab, new Vector2(Mathf.Cos(angle) * (circleArea.radius + Random.Range(5, 10)), Mathf.Sin(angle) * (circleArea.radius + Random.Range(5, 10))), Quaternion.identity);
redEnemy.GetComponent<EnemyRed>().speed = Random.Range( 2f, waveNumber / 2f + 4f);
redEnemy.GetComponent<EnemyRed>().rotationSpeed = Random.Range(20, 80);
redEnemies[i] = redEnemy;
}
enemiesKilled = 0;
}
}