25 lines
510 B
GDScript
25 lines
510 B
GDScript
class_name BoxReset
|
|
extends Area2D
|
|
|
|
@onready var reset_timer: Timer = $ResetTimer
|
|
|
|
@export var box: Box
|
|
|
|
func _ready():
|
|
reset_box(false)
|
|
|
|
func reset_box(has_offset: bool):
|
|
if !box.is_finished:
|
|
box.animation_player.play_backwards(&"complete")
|
|
box.position = position + (Vector2(8, 0) if has_offset else Vector2.ZERO)
|
|
|
|
|
|
func _on_body_entered(body):
|
|
if body is Player:
|
|
var diff = box.position.distance_to(position)
|
|
if diff > 12:
|
|
reset_timer.start()
|
|
|
|
func _on_reset_timer_timeout():
|
|
reset_box(true)
|