forked from Myyyvothrr/1gam-dungeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboss.cs
198 lines (147 loc) · 5.47 KB
/
boss.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
using UnityEngine;
using System.Collections;
public class boss : MonoBehaviour
{
public int hitpoints = 500;
private GameObject _player;
public Transform head_bone;
public GameObject fireball_prefab;
public GameObject fireball_left_spawnpoint;
public GameObject fireball_right_spawnpoint;
public int damage = 10;
public GameObject mage_prefab;
public GameObject mage_spawn_pos;
public GameObject attack_explosion;
private bool _killed = false;
public GameObject player_prefab;
void Start()
{
GetComponentInChildren<SkinnedMeshRenderer>().enabled = false;
animation["Begin"].speed = 0.25f;
animation["Idle"].speed = 0.5f;
animation["Attack1"].speed = 0.25f;
animation["Attack2"].speed = 0.5f;
animation["Attack3"].speed = 0.25f;
animation["Death"].speed = 0.5f;
animation["Looking"].speed = 0.125f;
_player = GameObject.Find("/player");
if (_player == null)
{
_player = (GameObject)Instantiate(player_prefab);
_player.name = "player";
}
_player.transform.position = new Vector3(0, 3, 105);
_player.transform.rotation = Quaternion.Euler(0, 180, 0);
StartCoroutine(wait_for_player());
}
void Update()
{
}
IEnumerator wait_for_player()
{
while (true)
{
if (Vector3.Distance(transform.position, _player.transform.position) > 195)
yield return new WaitForSeconds(1f);
else
break;
}
animation.CrossFade("Begin", 0f);
yield return new WaitForSeconds(0.01f);
GetComponentInChildren<SkinnedMeshRenderer>().enabled = true;
yield return new WaitForSeconds(10f);
animation.CrossFade("Idle", 0.5f);
StartCoroutine(attack());
}
IEnumerator attack()
{
while (true)
{
yield return new WaitForSeconds(Random.Range(2, 5));
if (_killed)
break;
switch (Random.Range(0, 5))
{
case 0:
{
animation.CrossFade("Idle", 0.2f);
yield return new WaitForSeconds(Random.Range(1f, 3f));
break;
}
case 1:
{
animation.CrossFade("Attack1", 0.2f);
yield return new WaitForSeconds(2.5f);
GameObject o = (GameObject)Instantiate(fireball_prefab, fireball_left_spawnpoint.transform.position, Quaternion.identity);
o.BroadcastMessage("set_player_pos", _player.transform.position);
o.BroadcastMessage("set_damage", damage);
o = (GameObject)Instantiate(fireball_prefab, fireball_right_spawnpoint.transform.position, Quaternion.identity);
o.BroadcastMessage("set_player_pos", _player.transform.position);
o.BroadcastMessage("set_damage", damage);
yield return new WaitForSeconds(2.75f);
break;
}
case 2:
{
animation.CrossFade("Attack2", 0.2f);
yield return new WaitForSeconds(3f);
mage_spawn_pos.audio.Play();
yield return new WaitForSeconds(1f);
for (int i = 0; i < 10; ++i)
{
Vector3 pos = mage_spawn_pos.transform.position;
pos.x += Random.Range(-10f, 10f);
pos.y = 0f;
pos.z += Random.Range(-10f, 10f);
Instantiate(attack_explosion, pos, Quaternion.identity);
}
yield return new WaitForSeconds(0.05f);
break;
}
case 3:
{
animation.CrossFade("Attack3", 0.2f);
yield return new WaitForSeconds(4f);
Instantiate(mage_prefab, mage_spawn_pos.transform.position, Quaternion.identity);
yield return new WaitForSeconds(1.5f);
break;
}
case 4:
{
animation.CrossFade("Looking", 0.2f);
yield return new WaitForSeconds(15f);
break;
}
}
}
}
/* void LateUpdate()
{
head_bone.rotation = Quaternion.RotateTowards(head_bone.rotation, Quaternion.LookRotation(_player.transform.position - head_bone.position, Vector3.up), 360f);
}*/
void receive_damage(int amount)
{
if (_killed)
return;
hitpoints -= amount;
if (hitpoints <= 0)
{
_killed = true;
animation.CrossFade("Death", 0.1f);
StartCoroutine(death());
}
}
IEnumerator death()
{
yield return new WaitForSeconds(8f);
Destroy(gameObject);
Application.LoadLevel(2);
}
void OnTriggerEnter(Collider other)
{
if (_killed)
return;
if (other.gameObject.tag.Equals("Player"))
other.gameObject.SendMessage("receive_damage", damage);
}
}