/
RockLevelMotherStarScript.cs
executable file
·191 lines (176 loc) · 8.16 KB
/
RockLevelMotherStarScript.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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RockLevelMotherStarScript : MonoBehaviour {
bool instantiateChildStars, moveRight, jewelPicked, startDecent, tutorialLevel, bombInstantiated;
public GameObject greenChildStar, redChildStar, whiteChildStar, purpleChildStar, blueChildStar, orangeChildStar, target;
GameObject childStar, instantiatedStar, instantiatedTarget, targetJewel;
float timeStamp, cooldown, targetX, targetY;
int childStarCount, row, col, tutorialNumber;
List<GameObject> childStarArray, jewelList;
RockLevelChildStarMovement childStarMovement;
RockLevelInstantiator instantiator;
RockLevelJewelMovement jewelMovement;
RockLevelTouchHandler touchHandler;
RockLevelFiveInARow fiveInARow;
RockLevelDeleteJewels deleteJewels;
PowerPercentageController powerPercentageController;
RockLevelBombHandler bombHandler;
SoundHandler soundHandler;
// Use this for initialization
void Start () {
cooldown = .1f;
childStarCount = 0;
GetChildStar ();
instantiator = GameObject.Find ("Level Controller").GetComponent<RockLevelInstantiator> ();
GetComponent<Rigidbody2D>().AddTorque (540);
deleteJewels = GameObject.Find ("Level Controller").GetComponent<RockLevelDeleteJewels> ();
touchHandler = GameObject.Find ("Level Controller").GetComponent<RockLevelTouchHandler> ();
fiveInARow = GameObject.Find ("Level Controller").GetComponent<RockLevelFiveInARow> ();
powerPercentageController = GameObject.Find ("Level Controller").GetComponent<PowerPercentageController> ();
soundHandler = GameObject.Find ("Game Manager").GetComponent<SoundHandler> ();
bombHandler = GameObject.Find ("Level Controller").GetComponent<RockLevelBombHandler> ();
if (GameObject.Find ("Mountain Level Two ID") != null) {
tutorialLevel = true;
}
tutorialNumber = 0;
jewelList = new List<GameObject> ();
jewelPicked = false;
// targetX = Random.Range (-2f, 2f);
// targetY = 4.5f;
targetX = transform.position.x;
targetY = transform.position.y;
childStarArray = new List<GameObject> ();
}
// Update is called once per frame
void Update () {
if (!instantiateChildStars)
transform.Translate ((targetX - transform.position.x) * .1f, (targetY - transform.position.y) * .1f, 0, Space.World);
if (!instantiateChildStars && Mathf.Abs (targetX - transform.position.x) < .05f && Mathf.Abs (targetY - transform.position.y) < .05f) {
instantiateChildStars = true;
timeStamp = Time.time;
moveRight = true;
}
if (instantiateChildStars && childStarCount < 12) {
childStarCount++;
if (!tutorialLevel && powerPercentageController.IsWithinPercentage () && !bombInstantiated) {
bombInstantiated = true;
InstantiateBombSeekingChildStars ();
} else
InstantiateChildStars ();
timeStamp = Time.time;
if (childStarCount == 12) {
cooldown = .4f;
timeStamp = Time.time;
startDecent = true;
}
}
if (startDecent && Time.time > timeStamp + cooldown) {
foreach (GameObject a in childStarArray) {
childStarMovement = a.GetComponent<RockLevelChildStarMovement> ();
childStarMovement.StartDecent ();
}
soundHandler.PlayPowerShot ();
fiveInARow.GetMotherStarList ().Remove (gameObject);
Destroy (gameObject);
}
}
void InstantiateBombSeekingChildStars () {
GameObject randomBomb = bombHandler.GetRandomBomb ();
if (randomBomb == null) {
InstantiateChildStars ();
return;
}
instantiatedStar = (GameObject)Instantiate (childStar, new Vector3 (gameObject.transform.position.x, gameObject.transform.position.y, -15), Quaternion.identity);
childStarMovement = instantiatedStar.GetComponent<RockLevelChildStarMovement> ();
row = randomBomb.GetComponent<RockLevelJewelMovement> ().GetRow ();
col = randomBomb.GetComponent<RockLevelJewelMovement> ().GetCol ();
while (instantiator.GetJewelGridGameObject (row, col) == null) {
row = Random.Range (0, 9);
col = Random.Range (0, 9);
}
jewelMovement = instantiator.GetJewelGridGameObject (row, col).GetComponent<RockLevelJewelMovement> ();
while (jewelMovement.GetMoving () || jewelList.Contains (instantiator.GetJewelGridGameObject (row, col))) {
row = Random.Range (0, 9);
col = Random.Range (0, 9);
while (instantiator.GetJewelGridGameObject (row, col) == null) {
row = Random.Range (0, 9);
col = Random.Range (0, 9);
}
jewelMovement = instantiator.GetJewelGridGameObject (row, col).GetComponent<RockLevelJewelMovement> ();
}
childStarMovement = instantiatedStar.GetComponent<RockLevelChildStarMovement> ();
childStarArray.Add (instantiatedStar);
fiveInARow.GetChildStarList ().Add (instantiatedStar);
jewelList.Add (instantiator.GetJewelGridGameObject (row, col));
instantiatedTarget = (GameObject)Instantiate (target, new Vector3 (-2.45f + (col * .6125f), 2.591252f - (row * .6097268f), -23), Quaternion.identity);
childStarMovement.SetTargetPosition (instantiator.GetJewelGridGameObject (row, col).transform.position, row, col, instantiatedTarget);
}
void InstantiateChildStars () {
instantiatedStar = (GameObject)Instantiate (childStar, new Vector3 (gameObject.transform.position.x, gameObject.transform.position.y, -15), Quaternion.identity);
childStarMovement = instantiatedStar.GetComponent<RockLevelChildStarMovement> ();
if (!tutorialLevel) {
row = Random.Range (0, 9);
col = Random.Range (0, 9);
while (IsBomb (instantiator.GetJewelGridGameObject (row, col).tag) || instantiator.GetJewelGridGameObject (row, col) == null) {
row = Random.Range (0, 9);
col = Random.Range (0, 9);
}
jewelMovement = instantiator.GetJewelGridGameObject (row, col).GetComponent<RockLevelJewelMovement> ();
while (IsBomb (instantiator.GetJewelGridGameObject (row, col).tag) || jewelMovement.GetMoving () || jewelList.Contains (instantiator.GetJewelGridGameObject (row, col))) {
row = Random.Range (0, 9);
col = Random.Range (0, 9);
while (instantiator.GetJewelGridGameObject (row, col) == null) {
row = Random.Range (0, 9);
col = Random.Range (0, 9);
}
jewelMovement = instantiator.GetJewelGridGameObject (row, col).GetComponent<RockLevelJewelMovement> ();
}
} else {
InstantiateTutorailChildStars ();
jewelMovement = instantiator.GetJewelGridGameObject (row, col).GetComponent<RockLevelJewelMovement> ();
}
childStarMovement = instantiatedStar.GetComponent<RockLevelChildStarMovement> ();
// childStarMovement.StartDecent ();
// jewelMovement.targetForExplosion ();
childStarArray.Add (instantiatedStar);
fiveInARow.GetChildStarList ().Add (instantiatedStar);
jewelList.Add (instantiator.GetJewelGridGameObject (row, col));
instantiatedTarget = (GameObject)Instantiate (target, new Vector3 (-2.45f + (col * .6125f), 2.591252f - (row * .6097268f), -23), Quaternion.identity);
childStarMovement.SetTargetPosition (instantiator.GetJewelGridGameObject (row, col).transform.position, row, col, instantiatedTarget);
}
void InstantiateTutorailChildStars () {
switch (tutorialNumber) {
case 0: row = 1; col = 8; break;
case 1: row = 2; col = 2; break;
case 2: row = 3; col = 2; break;
case 3: row = 4; col = 3; break;
case 4: row = 5; col = 1; break;
case 5: row = 6; col = 7; break;
case 6: row = 7; col = 5; break;
case 7: row = 8; col = 3; break;
case 8: row = 7; col = 7; break;
case 9: row = 6; col = 2; break;
case 10: row = 5; col = 4; break;
case 11: row = 4; col = 2; break;
}
tutorialNumber++;
jewelMovement = instantiator.GetJewelGridGameObject (row, col).GetComponent<RockLevelJewelMovement> ();
}
void GetChildStar () {
switch (gameObject.name) {
case "Red Mother Star(Clone)": childStar = redChildStar; break;
case "Green Mother Star(Clone)": childStar = greenChildStar; break;
case "White Mother Star(Clone)": childStar = whiteChildStar; break;
case "Blue Mother Star(Clone)": childStar = blueChildStar; break;
case "Orange Mother Star(Clone)": childStar = orangeChildStar; break;
case "Purple Mother Star(Clone)": childStar = purpleChildStar; break;
}
}
public bool JewelListContains (GameObject jewel) {
return jewelList.Contains (jewel);
}
bool IsBomb (string tag) {
return (tag == "Blue Bomb" || tag == "Green Bomb" || tag == "Orange Bomb" || tag == "Purple Bomb" || tag == "Red Bomb" || tag == "White Bomb");
}
}