Refactored and documented boss spawner, destroy area and ghost
This commit is contained in:
parent
8c11ee3000
commit
75194e1700
4 changed files with 21 additions and 12 deletions
|
|
@ -6,6 +6,7 @@ func _ready() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _on_water_water_reached_max_height() -> void:
|
func _on_water_water_reached_max_height() -> void:
|
||||||
|
# The boss spawns once the water has risen to its maximum height.
|
||||||
var node = boss.instantiate()
|
var node = boss.instantiate()
|
||||||
add_sibling(node)
|
add_sibling(node)
|
||||||
node.position = %Player.position + %Player.earth_aligner.local_from_global(Vector2.UP) * 1000;
|
node.position = %Player.position + %Player.earth_aligner.local_from_global(Vector2.UP) * 1000;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
|
# Attach this to an object to make it destructible
|
||||||
func destroy():
|
func destroy():
|
||||||
get_parent().queue_free()
|
get_parent().queue_free()
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,20 @@
|
||||||
extends Area2D
|
extends Area2D
|
||||||
@onready var earth_aligner = $EarthAligner
|
@onready var player : CharacterBody2D = get_tree().get_root().get_node_or_null("main/Player")
|
||||||
|
var target : CharacterBody2D
|
||||||
|
|
||||||
|
# Base stats
|
||||||
var speed = 100
|
var speed = 100
|
||||||
var damage = 1
|
var damage = 1
|
||||||
var player : CharacterBody2D
|
|
||||||
var target : CharacterBody2D
|
|
||||||
var current_knockback = Vector2.ZERO
|
|
||||||
var knockback_weight = 800
|
|
||||||
|
|
||||||
|
# Aggro range determines at which distance the ghost targets the player,
|
||||||
|
# Chase range determines at which distance the ghost stops pursuing the player.
|
||||||
var aggro_range = 900
|
var aggro_range = 900
|
||||||
var chase_range = 1400
|
var chase_range = 1400
|
||||||
|
|
||||||
|
var current_knockback = Vector2.ZERO
|
||||||
|
var knockback_weight = 800
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
player = get_tree().get_root().get_node_or_null("main/Player")
|
|
||||||
$AnimatedSprite2D.play("default")
|
$AnimatedSprite2D.play("default")
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
|
@ -19,28 +22,32 @@ func _process(delta: float) -> void:
|
||||||
return
|
return
|
||||||
|
|
||||||
var dist = (position - player.position).length()
|
var dist = (position - player.position).length()
|
||||||
|
# Set target based on aggression range and whether target is already set
|
||||||
if(dist > chase_range):
|
if(dist > chase_range):
|
||||||
target = null
|
target = null
|
||||||
elif(target == null and dist <= aggro_range):
|
elif(target == null and dist <= aggro_range):
|
||||||
target = player
|
target = player
|
||||||
|
|
||||||
|
# Move towards the target at constant speed
|
||||||
if(target!=null):
|
if(target!=null):
|
||||||
var motion = -(position - target.position).normalized() * speed
|
var motion = -(position - target.position).normalized() * speed
|
||||||
self.position += motion * delta * min(1, dist/(motion.length()*delta))
|
self.position += motion * delta * min(1, dist/(motion.length()*delta))
|
||||||
|
|
||||||
|
# Process knockback
|
||||||
self.position += current_knockback * delta
|
self.position += current_knockback * delta
|
||||||
current_knockback = current_knockback/pow(1.3, 60*delta)
|
current_knockback = current_knockback/pow(1.3, 60*delta)
|
||||||
|
|
||||||
if(self.overlaps_body(player)):
|
if(self.overlaps_body(player)):
|
||||||
player.hurt(damage, self.global_position-player.global_position)
|
player.hurt(damage, self.global_position-player.global_position)
|
||||||
|
|
||||||
func _on_death():
|
func _on_death():
|
||||||
|
# First free all other children, then wait for Death Sound to finish
|
||||||
for child in get_children():
|
for child in get_children():
|
||||||
if not child is AudioStreamPlayer2D:
|
if not child is AudioStreamPlayer2D:
|
||||||
child.queue_free()
|
child.queue_free()
|
||||||
await $AudioStreamPlayer2D.finished
|
await $HurtSound.finished
|
||||||
self.queue_free()
|
self.queue_free()
|
||||||
|
|
||||||
func _on_damage_taken(_damage : int, dir: Vector2, _id):
|
func _on_damage_taken(_damage : int, dir: Vector2, _id):
|
||||||
current_knockback = - dir * knockback_weight
|
current_knockback = - dir * knockback_weight
|
||||||
$AudioStreamPlayer2D.play()
|
$HurtSound.play()
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ shape = SubResource("CircleShape2D_6attn")
|
||||||
|
|
||||||
[node name="EarthAligner" parent="." instance=ExtResource("3_obmiq")]
|
[node name="EarthAligner" parent="." instance=ExtResource("3_obmiq")]
|
||||||
|
|
||||||
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
|
[node name="HurtSound" type="AudioStreamPlayer2D" parent="."]
|
||||||
stream = ExtResource("7_eqcb8")
|
stream = ExtResource("7_eqcb8")
|
||||||
volume_db = 15.0
|
volume_db = 15.0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue