-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoss.gd
69 lines (57 loc) · 1.78 KB
/
Boss.gd
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
extends KinematicBody
signal victory()
signal boss_hp_changed()
const PROJECTILE_COOLDOWN_TIME = 4
const SWITCH_SHIELD_COOLDOWN_TIME = 10
const MAX_HP = 200
var hp = MAX_HP
var projectileCooldown = 2
var switchShieldCooldown = 0
var player
var activated = false
func _ready():
$BossShield.mesh.material.albedo_color = Color(1, 1, 1, 0.3)
set_process(true)
$BossShield.show()
pass
func _process(delta):
if(activated):
look_at_from_position(translation, player.translation, Vector3(0, 1, 0))
projectileCooldown -= delta
if(projectileCooldown <= 0): shotProjectile()
switchShieldCooldown -= delta
if(switchShieldCooldown <= 0): switchShield()
func init(playerNode):
player = playerNode
func startBossfight():
#destroy white shield
if(not activated):
self.add_to_group("WaterElemental")
updateShieldColor()
activated = true
func takeDamage(dmg):
hp -= dmg
emit_signal("boss_hp_changed")
if(hp <= 0):
emit_signal("victory")
queue_free()
func shotProjectile():
#substitute projectile by huge projectile
var projectile = preload("res://BossProjectile.tscn").instance()
projectile.shoot_at(translation + Vector3(0, 1, 0), player.translation + Vector3(0, 1, 0))
get_parent().add_child(projectile)
projectileCooldown = PROJECTILE_COOLDOWN_TIME
func switchShield():
if(self.is_in_group("WaterElemental")):
self.add_to_group("FireElemental")
self.remove_from_group("WaterElemental")
else:
self.add_to_group("WaterElemental")
self.remove_from_group("FireElemental")
updateShieldColor()
switchShieldCooldown = SWITCH_SHIELD_COOLDOWN_TIME
func updateShieldColor():
if(self.is_in_group("WaterElemental")):
$BossShield.mesh.material.albedo_color = Color(0, 0, 1, 0.3)
if(self.is_in_group("FireElemental")):
$BossShield.mesh.material.albedo_color = Color(1, 0, 0, 0.3)