2020-10-20 13:51:17 +00:00
|
|
|
extends Position2D
|
|
|
|
tool
|
|
|
|
export var node:PackedScene = null
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2020-11-25 20:07:47 +00:00
|
|
|
if not Engine.editor_hint:
|
|
|
|
GameState.connect("player_just_died", self,"_on_Player_died")
|
2020-10-26 12:21:11 +00:00
|
|
|
_spawn()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
|
|
if not Engine.editor_hint:
|
|
|
|
despawn()
|
|
|
|
|
|
|
|
|
2020-10-20 13:51:17 +00:00
|
|
|
|
|
|
|
func _on_VisibilityNotifier2D_screen_entered() -> void:
|
2020-10-26 12:21:11 +00:00
|
|
|
respawn()
|
|
|
|
|
|
|
|
func reset():
|
|
|
|
despawn()
|
2020-10-20 13:51:17 +00:00
|
|
|
respawn()
|
|
|
|
|
2020-10-26 12:21:11 +00:00
|
|
|
|
|
|
|
func despawn():
|
|
|
|
var current_node = get_node("node")
|
|
|
|
if current_node != null:
|
|
|
|
remove_child(current_node)
|
|
|
|
|
2020-10-20 13:51:17 +00:00
|
|
|
func respawn():
|
|
|
|
var current_node = get_node("node")
|
|
|
|
if current_node == null and node != null:
|
|
|
|
_spawn()
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
func _on_Player_died():
|
2020-11-25 20:07:47 +00:00
|
|
|
print("SPAWN - PLAYER DIED")
|
|
|
|
$RespawnTimer.start()
|
|
|
|
|
2020-10-20 13:51:17 +00:00
|
|
|
|
|
|
|
func _spawn():
|
|
|
|
var inst = node.instance()
|
|
|
|
inst.name = "node"
|
|
|
|
add_child(inst)
|
|
|
|
|
2020-11-25 20:07:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_RespawnTimer_timeout() -> void:
|
|
|
|
despawn()
|
|
|
|
if $VisibilityNotifier2D.is_on_screen():
|
|
|
|
respawn()
|