hero-mark-2/objects/collectibles/key.gd
2024-05-05 20:12:18 -04:00

32 lines
695 B
GDScript

extends Node2D
const SEMITONE := 1.05946
const TIMEOUT := 1000
const MAX_PITCH := 2.0
const STATIC = {
pitch = -1.0,
timeout = -1,
}
func _ready():
#Sync all coinframes
$AnimatedSprite.play()
func _on_Area2D_body_entered(body: Node) -> void:
#Collect
if body.is_in_group("player"):
Game.keys += 1
Game.score += 5
# pitch increase
if Time.get_ticks_msec() < STATIC.timeout:
STATIC.pitch = min(STATIC.pitch + 1.0, MAX_PITCH)
else:
STATIC.pitch = -1.0
STATIC.timeout = Time.get_ticks_msec() + TIMEOUT
Audio.play_sound(Audio.a_key,Audio.ac_collectible, pow(SEMITONE, STATIC.pitch))
if Game._get_shards() >= 5 && Game.keys == 50:
Audio.great_job()
queue_free()