src / stages / gimmicks / strawberry / strawberry.gd

Code

extends Area2D

@onready var player : Player
@export var obtained : bool = false
const OFFSET := Vector2(0, -200)


func _ready() -> void:
	if obtained: hide()


func reset() -> void:
	player = null
	%Pivot.position = Vector2(0, 0)
	if obtained: hide()
	play(&'RESET')
	play.call_deferred(&'idle')


func _physics_process(_delta: float) -> void:
	if player:
		var target := player.global_position + OFFSET
		%Pivot.global_position = %Pivot.global_position.lerp(target, 0.1)


func ascend() -> void:
	play(&'ascend')
	obtained = true


func play(key: StringName) -> void:
	%AnimationPlayer.play(key)


func _on_hit_area_entered(area: Area2D) -> void:
	player = area.owner as Player


func _on_area_entered(_area: Area2D) -> void:
	if not obtained and player: ascend()