-
Notifications
You must be signed in to change notification settings - Fork 0
/
BossScript.cs
256 lines (243 loc) · 8.23 KB
/
BossScript.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
using UnityEngine;
using System.Collections;
public class BossScript : MonoBehaviour {
private float angle = 0;
public float seconds = 5;
public float bulletSpeed = 0.2f;
private float speed; //2*PI in degress is 360, so you get 5 seconds to complete a circle
public float radius = 2;
private Vector2 pos = Vector2.zero;
private Vector2 origpos = Vector2.zero;
public float BulletSpawnX = 1f;
public float BulletSpawnY = 1f;
public GameObject bomb;
public GameObject explosion;
public int bossHP = 20;
private BoxCollider2D box;
private Score scores;
public int points = 250;
public GameObject stopTrigger;
public static float bTime = 0f;
public bool miniBoss = false;
public bool laserBoss = false;
private SpriteRenderer rend;
private Color32 origcolor;
public static float explodeTime = 10f;
public float explodeTime1 = 10f;
public bool boss2 = false;
void Start () {
explodeTime = explodeTime1;
StartCoroutine("Pattern");
origpos = transform.position;
speed = (2 * Mathf.PI) / seconds;
box = GetComponent<BoxCollider2D>();
box.enabled = false;
scores = GameObject.Find("Canvas").GetComponent<Score>();
rend = GetComponent<SpriteRenderer>();
origcolor = rend.color;
if(MainMenu.player2)
{
bossHP = bossHP * 2;
}
}
void Update () {
if (!boss2)
{
angle += speed * Time.deltaTime;
pos.x = Mathf.Cos(angle) * radius + origpos.x;
pos.y = Mathf.Sin(angle) * radius + origpos.y;
transform.position = pos;
}
if (bossHP <= 0)
{
Instantiate(explosion, transform.position, new Quaternion());
if (miniBoss)
{
MoveForward.stop = false;
}
MoveForward.slow = false;
BackgroundScroll.moving = true;
Destroy(stopTrigger);
if (scores.cmb == true)
{
scores.score += points * scores.combo;
}
if (scores.cmb2 == true)
{
scores.score2 += points * scores.combo2;
}
if(!miniBoss)
{
Pause.explode = true;
}
Destroy(gameObject, explodeTime);
}
if(ShieldHitBox.shieldHP <= 0)
{
box.enabled = true;
}
}
void Shoot(float pitch)
{
GameObject pNewObject;
pNewObject = Instantiate(bomb) as GameObject;
pNewObject.transform.rotation = transform.rotation;
Vector2 pos = transform.position;
pos.x += BulletSpawnX;
pos.y += BulletSpawnY;
pNewObject.transform.position = pos;
pNewObject.GetComponent<Rigidbody2D>().velocity = new Vector2(18f, -16f) * -bulletSpeed / pitch;
}
IEnumerator Pattern()
{
yield return null;
while (true)
{
if (!miniBoss)
{
//yield return new WaitForSeconds(2f);
Shoot(0.5f);
bTime = 1.8f;
yield return new WaitForSeconds(0.7f);
Shoot(0.61f);
bTime = 1.5f;
yield return new WaitForSeconds(0.7f);
Shoot(0.9f);
bTime = 1.2f;
yield return new WaitForSeconds(0.7f);
Shoot(0.3f);
bTime = 1.7f;
yield return new WaitForSeconds(0.7f);
Shoot(0.42f);
bTime = 1.7f;
yield return new WaitForSeconds(0.9f);
Shoot(0.7f);
bTime = 1.2f;
yield return new WaitForSeconds(0.7f);
Shoot(0.56f);
bTime = 1.4f;
yield return new WaitForSeconds(0.7f);
Shoot(0.48f);
bTime = 1.7f;
yield return new WaitForSeconds(0.7f);
Shoot(0.3f);
bTime = 1.7f;
yield return new WaitForSeconds(0.7f);
Shoot(0.42f);
bTime = 1.7f;
yield return new WaitForSeconds(1.1f);
}
if (laserBoss)
{
Shoot(0.5f);
bTime = 2f;
yield return new WaitForSeconds(0.7f);
Shoot(0.61f);
bTime = 1.7f;
yield return new WaitForSeconds(0.7f);
Shoot(0.9f);
bTime = 1.4f;
yield return new WaitForSeconds(0.7f);
Shoot(0.3f);
bTime = 1.9f;
yield return new WaitForSeconds(0.7f);
Shoot(0.42f);
bTime = 1.9f;
yield return new WaitForSeconds(0.9f);
Shoot(0.7f);
bTime = 1.4f;
yield return new WaitForSeconds(0.7f);
Shoot(0.56f);
bTime = 1.6f;
yield return new WaitForSeconds(0.7f);
Shoot(0.48f);
bTime = 1.9f;
yield return new WaitForSeconds(0.7f);
Shoot(0.3f);
bTime = 1.9f;
yield return new WaitForSeconds(0.7f);
Shoot(0.42f);
bTime = 1.9f;
yield return new WaitForSeconds(1.1f);
}
if (miniBoss)
{
Shoot(0.5f);
bTime = 1.8f;
yield return new WaitForSeconds(0.5f);
Shoot(0.61f);
bTime = 1.5f;
yield return new WaitForSeconds(0.5f);
Shoot(0.9f);
bTime = 1.2f;
yield return new WaitForSeconds(0.5f);
Shoot(0.42f);
bTime = 1.7f;
yield return new WaitForSeconds(0.7f);
Shoot(0.7f);
bTime = 1.2f;
yield return new WaitForSeconds(0.5f);
Shoot(0.56f);
bTime = 1.4f;
yield return new WaitForSeconds(0.5f);
Shoot(0.48f);
bTime = 1.7f;
yield return new WaitForSeconds(0.5f);
Shoot(0.42f);
bTime = 1.7f;
yield return new WaitForSeconds(0.9f);
}
}
}
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.tag == "p1Bullet" || collider.tag == "p1Bullet2" || collider.tag == "p1Bullet3" || collider.tag == "p1Bomb")
{
scores.hit++;
scores.timer = scores.cTime;
scores.combo++;
if(scores.cmb == false)
{
scores.combo = 0;
scores.score += points;
}
}
if (collider.tag == "p2Bullet" || collider.tag == "p2Bullet2" || collider.tag == "p2Bullet3" || collider.tag == "p2Bomb")
{
scores.hit2++;
scores.timer2 = scores.cTime;
scores.combo2++;
if (scores.cmb2 == false)
{
scores.combo2 = 0;
scores.score2 += points;
}
}
if (collider.tag == "p1Bullet" || collider.tag == "p2Bullet")
{
bossHP -= Projectile.bullet1Dmg;
StartCoroutine("flash", 0);
}
if (collider.tag == "p1Bullet2" || collider.tag == "p2Bullet2")
{
bossHP -= Projectile.bullet2Dmg;
StartCoroutine("flash", 0);
}
if (collider.tag == "p1Bullet3" || collider.tag == "p2Bullet3")
{
bossHP -= Projectile.bullet3Dmg;
StartCoroutine("flash", 0);
}
if (collider.tag == "p1Bomb" || collider.tag == "p2Bomb")
{
bossHP -= Projectile.bombDmg;
StartCoroutine("flash", 0);
}
}
IEnumerator flash()
{
rend.color = new Color32(255, 117, 152, 255);
yield return new WaitForSeconds(0.1f);
rend.color = origcolor;
}
}