Adds a timer between each stimulus for the hear and find minigames. Adds a timer to repeat stimuli in the hear and find minigames.

This commit is contained in:
Dylan Sarrazyn
2024-04-08 10:08:57 +02:00
committed by BimDav
parent 57180fabd3
commit 2173fc763b
9 changed files with 77 additions and 15 deletions
@@ -1,6 +1,27 @@
extends Minigame
class_name HearAndFindMinigame
signal stimuli_heard(is_heard : bool)
# Time before a new stimulus when the previous one is found
@export var between_stimuli_time : float = 2.
# Time before the current stimulus is repeated
@export var stimulus_repeat_time : float = 15
@onready var stimulus_timer: Timer = $StimulusTimer
# Define if the current stimulus have been heard by the player. The stimuli can't be pressed if this is false
var is_stimulus_heard: bool = false:
set(value):
is_stimulus_heard = value
stimuli_heard.emit(value)
func _start() -> void:
stimulus_timer.wait_time = stimulus_repeat_time
_play_current_stimulus_phoneme()
# Find the stimuli and distractions of the minigame.
# For this type of minigame, only vowels and syllables are allowed
func _find_stimuli_and_distractions() -> void:
@@ -109,6 +130,25 @@ func _play_current_stimulus_phoneme() -> void:
if not current_stimulus or not current_stimulus.has("Phoneme"):
return
await audio_player.play_phoneme(current_stimulus.Phoneme)
is_stimulus_heard = true
stimulus_timer.start()
# ------------ Connections ------------
func _on_stimulus_pressed(node) -> bool:
if not is_stimulus_heard:
return false
stimulus_timer.stop()
return true
func _on_stimulus_timer_timeout():
_play_current_stimulus_phoneme()
# ------------ UI Callbacks ------------
@@ -116,6 +156,8 @@ func _play_current_stimulus_phoneme() -> void:
func _on_current_progression_changed() -> void:
if current_progression > 0:
is_stimulus_heard = false
await get_tree().create_timer(between_stimuli_time).timeout
_play_current_stimulus_phoneme()
@@ -5,5 +5,12 @@
[node name="HearAndFindMinigame" instance=ExtResource("1_fbfdj")]
script = ExtResource("2_v8ldm")
between_stimuli_time = 2.0
stimulus_repeat_time = 15.0
max_number_of_lives = 3
max_progression = 10
[node name="StimulusTimer" type="Timer" parent="." index="5"]
wait_time = 3.0
[connection signal="timeout" from="StimulusTimer" to="." method="_on_stimulus_timer_timeout"]
+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 = &"idle1"
animation = &"idle2"
autoplay = "idle1"
frame_progress = 0.751507
frame_progress = 0.874361
centered = false
offset = Vector2(-5, 0)
+8 -4
View File
@@ -50,16 +50,15 @@ 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)
holes.append(hole)
# Launch the minigame
func _start() -> void:
super()
_play_current_stimulus_phoneme()
# Spawn a set amount of crabs in random holes
for i in range(int(3.0 * holes.size() / 4.0)):
_on_hole_crab_despawned()
@@ -74,9 +73,14 @@ func _get_difficulty_settings() -> DifficultySettings:
func _on_hole_stimulus_hit(stimulus: Dictionary, hole: Hole) -> void:
if not is_stimulus_heard:
return
# 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()
+1 -1
View File
@@ -14,7 +14,7 @@ script = ExtResource("2_gierf")
difficulty = 2
minigame_name = "Crabs"
lesson_nb = 10
difficulty = 4
difficulty = 2
lesson_nb = 3
max_number_of_lives = 5
max_progression = 5
+7 -2
View File
@@ -76,6 +76,12 @@ func is_button_pressed_with_limit(future):
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()
@@ -85,14 +91,13 @@ func wrong() -> void:
func _on_crab_hit(stimulus: Dictionary) -> void:
stimulus_hit.emit(stimulus)
var crab_x : float = -crab.size.x / 2
crab.set_button_active(false)
crab_audio_stream_player.stop_playing()
stimulus_hit.emit(stimulus)
# Move the crab up and rotate
var tween: = create_tween()
tween.tween_property(crab, "position", Vector2(crab_x, -180), 0.5)
+1 -1
View File
@@ -68,7 +68,7 @@ unique_name_in_owner = true
scale = Vector2(2.15054, 2.15054)
sprite_frames = ExtResource("5_bh1cr")
animation = &"idle"
frame_progress = 0.139471
frame_progress = 0.678924
centered = false
offset = Vector2(-0.000205994, 0.00019455)
@@ -29,7 +29,6 @@ var blocking_jellyfish: Array[Jellyfish] = []
func _start() -> void:
super()
_play_current_stimulus_phoneme()
spawn_timer.start()
@@ -115,7 +114,7 @@ func _spawn() -> void:
blocking_jellyfish.insert(found_ind, new_jellyfish)
# Connects the new jellyfish with the pressed signal
new_jellyfish.pressed.connect(_on_jellyfish_pressed.bind(new_jellyfish))
new_jellyfish.pressed.connect(_on_stimulus_pressed.bind(new_jellyfish))
func _get_difficulty_settings() -> DifficultySettings:
@@ -130,10 +129,12 @@ func _on_spawn_timer_timeout() -> void:
spawn_timer.wait_time = _get_difficulty_settings().spawn_time
func _on_jellyfish_pressed(jellyfish: Jellyfish) -> void:
func _on_stimulus_pressed(jellyfish: Jellyfish) -> bool:
if not super(jellyfish):
return false
# Disconnect the jellyfish
jellyfish.pressed.disconnect(_on_jellyfish_pressed)
jellyfish.pressed.disconnect(_on_stimulus_pressed)
# Log the answer
_log_new_response(jellyfish.stimulus, _get_current_stimulus())
@@ -164,6 +165,8 @@ func _on_jellyfish_pressed(jellyfish: Jellyfish) -> void:
# Replay the current stimulus
if not is_right:
_play_current_stimulus_phoneme()
return true
func _on_highlight_timer_timeout():
@@ -11,8 +11,9 @@
[node name="JellyfishMinigame" instance=ExtResource("1_hauef")]
script = ExtResource("2_gnjlp")
lesson_nb = 6
lesson_nb = 12
difficulty = 4
stimuli_ratio = 0.6
intro_kalulu_speech = ExtResource("3_6sswr")
help_kalulu_speech = ExtResource("2_7li38")
win_kalulu_speech = ExtResource("3_ar7nu")