Desactivate the crabs during the time between two stimuli.

This commit is contained in:
Dylan Sarrazyn
2024-04-08 10:08:57 +02:00
committed by BimDav
parent 2173fc763b
commit 34333e2a8c
4 changed files with 53 additions and 39 deletions
@@ -1,7 +1,7 @@
extends Minigame
class_name HearAndFindMinigame
signal stimuli_heard(is_heard : bool)
signal stimulus_heard(is_heard : bool)
# Time before a new stimulus when the previous one is found
@export var between_stimuli_time : float = 2.
@@ -14,7 +14,7 @@ signal stimuli_heard(is_heard : bool)
var is_stimulus_heard: bool = false:
set(value):
is_stimulus_heard = value
stimuli_heard.emit(value)
stimulus_heard.emit(value)
func _start() -> void:
@@ -139,7 +139,7 @@ func _play_current_stimulus_phoneme() -> void:
# ------------ Connections ------------
func _on_stimulus_pressed(node) -> bool:
func _on_stimulus_pressed(_node) -> bool:
if not is_stimulus_heard:
return false
+2 -2
View File
@@ -247,9 +247,9 @@ sprites = [NodePath("AnimatedSprite2D")]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Body/SpriteControl"]
unique_name_in_owner = true
sprite_frames = SubResource("SpriteFrames_g5q5i")
animation = &"idle2"
animation = &"idle1"
autoplay = "idle1"
frame_progress = 0.874361
frame_progress = 0.9976
centered = false
offset = Vector2(-5, 0)
+1 -4
View File
@@ -50,8 +50,7 @@ func _setup_minigame() -> void:
if not Engine.is_editor_hint():
hole.stimulus_hit.connect(_on_hole_stimulus_hit.bind(hole))
hole.crab_despawned.connect(_on_hole_crab_despawned)
stimuli_heard.connect(hole.set_crab_button_active)
stimulus_heard.connect(hole.on_stimulus_heard)
holes.append(hole)
@@ -79,8 +78,6 @@ func _on_hole_stimulus_hit(stimulus: Dictionary, hole: Hole) -> void:
# Logs the response
_log_new_response(stimulus, _get_current_stimulus())
# TODO Déplacer les animations des crabes ici
var is_right: = _is_stimulus_right(stimulus)
if is_right:
hole.right()
+47 -30
View File
@@ -15,6 +15,16 @@ const crab_scene: = preload("res://sources/minigames/crabs/crab/crab.tscn")
var crab: Crab
var stimulus_heard: bool = false:
set(value):
stimulus_heard = value
_set_crab_button_active(stimulus_heard and crab_visible)
var crab_visible: bool = false:
set(value):
crab_visible = value
_set_crab_button_active(stimulus_heard and crab_visible)
func spawn_crab(stimulus: Dictionary) -> void:
# Instantiate a new crab
@@ -42,7 +52,7 @@ func spawn_crab(stimulus: Dictionary) -> void:
crab_audio_stream_player.start_playing()
tween = create_tween()
tween.tween_property(crab, "position", Vector2(crab_x, -130.0), 0.5)
crab.set_button_active(true)
crab_visible = true
if await is_button_pressed_with_limit(tween.finished):
return
crab_audio_stream_player.stop_playing()
@@ -65,37 +75,10 @@ func spawn_crab(stimulus: Dictionary) -> void:
crab_despawned.emit()
func is_button_pressed_with_limit(future):
var coroutine: = Coroutine.new()
coroutine.add_future(crab.is_button_pressed)
coroutine.add_future(future)
await coroutine.join_either()
if coroutine.return_value[0]:
await _on_crab_hit(crab.stimulus)
return true
return false
func set_crab_button_active(is_active : bool):
if not crab:
return
crab.set_button_active(is_active)
func right() -> void:
await crab.right()
func wrong() -> void:
await crab.wrong()
func _on_crab_hit(stimulus: Dictionary) -> void:
stimulus_hit.emit(stimulus)
func despawn_crab() -> void:
var crab_x : float = -crab.size.x / 2
crab.set_button_active(false)
crab_visible = false
crab_audio_stream_player.stop_playing()
# Move the crab up and rotate
@@ -118,3 +101,37 @@ func _on_crab_hit(stimulus: Dictionary) -> void:
crab = null
crab_despawned.emit()
func is_button_pressed_with_limit(future) -> bool:
var coroutine: = Coroutine.new()
coroutine.add_future(crab.is_button_pressed)
coroutine.add_future(future)
await coroutine.join_either()
if coroutine.return_value[0]:
await _on_crab_hit(crab.stimulus)
return true
return false
func _set_crab_button_active(is_active : bool):
if crab:
crab.set_button_active(is_active)
func right() -> void:
crab.right()
despawn_crab()
func wrong() -> void:
crab.wrong()
despawn_crab()
func _on_crab_hit(stimulus: Dictionary) -> void:
stimulus_hit.emit(stimulus)
func on_stimulus_heard(is_heard : bool):
stimulus_heard = is_heard