item/fromage: reinitialisation timé

Un timer redéclenche l'apparition du fromage au bout d'un certain temps.
Il suffit de paramètrer la variable CHEESE_RESPAWN_TIME pour que ça soit
customisable à l'envie.
This commit is contained in:
Thomas Lavocat
2023-04-30 18:53:58 +02:00
parent 66383d3659
commit 273ca490c0
3 changed files with 42 additions and 4 deletions

View File

@@ -2,7 +2,24 @@ class_name NormalCheese extends Area2D
@onready var animation_player := $AnimationPlayer as AnimationPlayer
@onready var timer := $Timer as Timer
@export var CHEESE_RESPAWN_TIME : int = 1
var picked :bool = false
func _on_body_entered(body: Node2D) -> void:
animation_player.play(&"picked")
(body as Princess).cheese_collected.emit()
if not picked:
animation_player.play(&"picked")
(body as Princess).cheese_collected.emit()
picked = true
# Le fromage peut être à utilisation unique
if CHEESE_RESPAWN_TIME > 0:
timer.start(CHEESE_RESPAWN_TIME)
func _on_timer_timeout() -> void:
timer.stop()
animation_player.play(&"RESET")
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
if anim_name == "RESET":
animation_player.play(&"cheese")
picked = false