update
This commit is contained in:
@@ -1,4 +1,13 @@
|
||||
extends StaticBody3D
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("targetable")
|
||||
add_to_group("portals")
|
||||
EventBus.entity_died.connect(_on_entity_died)
|
||||
|
||||
func _on_entity_died(entity: Node) -> void:
|
||||
if entity == self:
|
||||
queue_free()
|
||||
|
||||
func _on_detection_area_body_entered(body: Node3D) -> void:
|
||||
if body is CharacterBody3D and body.name == "Player":
|
||||
EventBus.enemy_engaged.emit(self, body)
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
extends Node
|
||||
|
||||
const SPAWN_COUNT := 3
|
||||
var thresholds := [0.85, 0.70, 0.55, 0.40, 0.25, 0.10]
|
||||
var triggered: Array[bool] = [false, false, false, false, false, false]
|
||||
var enemy_scene: PackedScene = preload("res://scenes/enemy/enemy.tscn")
|
||||
|
||||
@onready var portal: StaticBody3D = get_parent()
|
||||
@onready var health: Node = get_parent().get_node("Health")
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if health.current_health <= 0:
|
||||
return
|
||||
var ratio: float = health.current_health / health.max_health
|
||||
for i in range(thresholds.size()):
|
||||
if not triggered[i] and ratio <= thresholds[i]:
|
||||
triggered[i] = true
|
||||
_spawn_enemies()
|
||||
|
||||
func _spawn_enemies() -> void:
|
||||
var spawned: Array = []
|
||||
for j in range(SPAWN_COUNT):
|
||||
var enemy: CharacterBody3D = enemy_scene.instantiate()
|
||||
var offset := Vector3(randf_range(-2, 2), 0, randf_range(-2, 2))
|
||||
portal.get_parent().add_child(enemy)
|
||||
enemy.global_position = portal.global_position + offset
|
||||
enemy.spawn_position = portal.global_position
|
||||
enemy.portal = portal
|
||||
spawned.append(enemy)
|
||||
EventBus.portal_spawn.emit(portal, spawned)
|
||||
@@ -1 +0,0 @@
|
||||
uid://begrg74oh76pu
|
||||
Reference in New Issue
Block a user