update
This commit is contained in:
34
scripts/portal/gate.gd
Normal file
34
scripts/portal/gate.gd
Normal file
@@ -0,0 +1,34 @@
|
||||
extends StaticBody3D
|
||||
|
||||
@export var target_scene: String = "res://scenes/dungeon/dungeon.tscn"
|
||||
@export var is_exit: bool = false
|
||||
|
||||
var active := false
|
||||
|
||||
func _ready() -> void:
|
||||
if not is_exit:
|
||||
if GameState.dungeon_cleared:
|
||||
queue_free()
|
||||
return
|
||||
get_tree().create_timer(0.5).timeout.connect(_check_overlapping)
|
||||
else:
|
||||
get_tree().create_timer(1.0).timeout.connect(func() -> void: active = true)
|
||||
|
||||
func _check_overlapping() -> void:
|
||||
active = true
|
||||
for body in $GateArea.get_overlapping_bodies():
|
||||
_on_gate_area_body_entered(body)
|
||||
|
||||
func _on_gate_area_body_entered(body: Node3D) -> void:
|
||||
if not active:
|
||||
return
|
||||
if body is CharacterBody3D and body.name == "Player":
|
||||
GameState.save_player(body)
|
||||
if is_exit:
|
||||
GameState.returning_from_dungeon = true
|
||||
else:
|
||||
GameState.portal_position = global_position
|
||||
call_deferred("_change_scene")
|
||||
|
||||
func _change_scene() -> void:
|
||||
get_tree().change_scene_to_file(target_scene)
|
||||
1
scripts/portal/gate.gd.uid
Normal file
1
scripts/portal/gate.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ctci5mc3cd2ck
|
||||
@@ -1,12 +1,23 @@
|
||||
extends StaticBody3D
|
||||
|
||||
const GATE_SCENE: PackedScene = preload("res://scenes/portal/gate.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("portals")
|
||||
EventBus.entity_died.connect(_on_entity_died)
|
||||
|
||||
func _on_entity_died(entity: Node) -> void:
|
||||
if entity == self:
|
||||
queue_free()
|
||||
if entity != self:
|
||||
return
|
||||
var gate: Node3D = GATE_SCENE.instantiate()
|
||||
gate.global_position = global_position
|
||||
get_parent().add_child(gate)
|
||||
var enemies := get_tree().get_nodes_in_group("enemies")
|
||||
for enemy in enemies:
|
||||
if is_instance_valid(enemy):
|
||||
enemy.queue_free()
|
||||
EventBus.portal_defeated.emit(self)
|
||||
queue_free()
|
||||
|
||||
func _on_detection_area_body_entered(body: Node3D) -> void:
|
||||
if body is CharacterBody3D and body.name == "Player":
|
||||
|
||||
Reference in New Issue
Block a user