Handles the spawn of the stimuli in the hear and find minigames.
This commit is contained in:
@@ -32,6 +32,13 @@ MusicManager="*res://sources/utils/autoloads/music_manager.tscn"
|
||||
Validation="*res://addons/godot-form-validator/validation.gd"
|
||||
OpeningCurtain="*res://sources/minigames/base/opening_curtain.tscn"
|
||||
|
||||
[debug]
|
||||
|
||||
gdscript/warnings/untyped_declaration=1
|
||||
gdscript/warnings/unsafe_property_access=1
|
||||
gdscript/warnings/unsafe_method_access=1
|
||||
gdscript/warnings/unsafe_call_argument=1
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=2560
|
||||
|
||||
@@ -2,6 +2,7 @@ extends Minigame
|
||||
class_name HearAndFindMinigame
|
||||
|
||||
signal stimulus_heard(is_heard : bool)
|
||||
signal stimulus_found()
|
||||
|
||||
# Time before a new stimulus when the previous one is found
|
||||
@export var between_stimuli_time : float = 2.
|
||||
@@ -19,7 +20,7 @@ var is_stimulus_heard: bool = false:
|
||||
|
||||
func _start() -> void:
|
||||
stimulus_timer.wait_time = stimulus_repeat_time
|
||||
_play_current_stimulus_phoneme()
|
||||
await _play_current_stimulus_phoneme()
|
||||
|
||||
|
||||
# Find the stimuli and distractions of the minigame.
|
||||
@@ -144,6 +145,11 @@ func _get_current_stimulus() -> Dictionary:
|
||||
return stimuli[current_progression % stimuli.size()]
|
||||
|
||||
|
||||
func _is_stimulus_found() -> bool:
|
||||
await stimulus_found
|
||||
return true
|
||||
|
||||
|
||||
func _is_stimulus_right(stimulus : Dictionary) -> bool:
|
||||
var current_stimulus := _get_current_stimulus()
|
||||
return stimulus == current_stimulus
|
||||
@@ -160,18 +166,34 @@ func _play_current_stimulus_phoneme() -> void:
|
||||
stimulus_timer.start()
|
||||
|
||||
|
||||
func _await_for_future_or_stimulus_found(future : Signal) -> bool:
|
||||
var coroutine: = Coroutine.new()
|
||||
coroutine.add_future(_is_stimulus_found)
|
||||
coroutine.add_future(future)
|
||||
await coroutine.join_either()
|
||||
|
||||
# If the stimulus was found BEFORE the future
|
||||
if coroutine.return_value[0]:
|
||||
return true
|
||||
return false
|
||||
|
||||
# ------------ Connections ------------
|
||||
|
||||
|
||||
func _on_stimulus_pressed(stimulus : Dictionary, _node) -> bool:
|
||||
func _on_stimulus_pressed(stimulus : Dictionary, node) -> bool:
|
||||
if not is_stimulus_heard:
|
||||
return false
|
||||
|
||||
# Stop the repeat timer
|
||||
stimulus_timer.stop()
|
||||
|
||||
# Log the answer
|
||||
_log_new_response(stimulus, _get_current_stimulus())
|
||||
|
||||
# Emit signal if needed
|
||||
if _is_stimulus_right(stimulus):
|
||||
stimulus_found.emit()
|
||||
|
||||
return true
|
||||
|
||||
|
||||
@@ -179,6 +201,10 @@ func _on_stimulus_timer_timeout():
|
||||
_play_current_stimulus_phoneme()
|
||||
|
||||
|
||||
func _on_stimulus_found():
|
||||
pass
|
||||
|
||||
|
||||
# ------------ UI Callbacks ------------
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,6 @@ max_number_of_lives = 3
|
||||
max_progression = 10
|
||||
|
||||
[node name="StimulusTimer" type="Timer" parent="." index="5"]
|
||||
wait_time = 3.0
|
||||
|
||||
[connection signal="stimulus_found" from="." to="." method="_on_stimulus_found"]
|
||||
[connection signal="timeout" from="StimulusTimer" to="." method="_on_stimulus_timer_timeout"]
|
||||
|
||||
@@ -249,7 +249,7 @@ unique_name_in_owner = true
|
||||
sprite_frames = SubResource("SpriteFrames_g5q5i")
|
||||
animation = &"idle1"
|
||||
autoplay = "idle1"
|
||||
frame_progress = 0.9976
|
||||
frame_progress = 0.0800428
|
||||
centered = false
|
||||
offset = Vector2(-5, 0)
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ var difficulty_settings: Array[DifficultySettings] = [
|
||||
|
||||
@onready var crab_zone: = $GameRoot/CrabZone
|
||||
|
||||
var stopped : bool = true
|
||||
var holes: Array[Hole] = []
|
||||
|
||||
|
||||
@@ -86,12 +85,9 @@ func _on_stimulus_pressed(stimulus: Dictionary, hole: Hole) -> bool:
|
||||
|
||||
|
||||
func _on_current_progression_changed() -> void:
|
||||
# TODO Stop the spawning of new crabs
|
||||
stopped = true
|
||||
# TODO Make all crabs despawn
|
||||
# Play the new stimulus
|
||||
await super()
|
||||
# TODO Restarts the spawning of crabs
|
||||
super()
|
||||
# Restarts the spawning of crabs
|
||||
_spawn_crabs()
|
||||
|
||||
|
||||
@@ -99,17 +95,14 @@ func _on_current_progression_changed() -> void:
|
||||
|
||||
# Spawn a set amount of crabs in random holes
|
||||
func _spawn_crabs() -> void:
|
||||
stopped = false
|
||||
for i in range(int(3.0 * holes.size() / 4.0)):
|
||||
_on_hole_crab_despawned()
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
|
||||
|
||||
func _on_hole_crab_despawned() -> void:
|
||||
if stopped:
|
||||
if await _await_for_future_or_stimulus_found(get_tree().create_timer(randf_range(0.1, 2.0)).timeout):
|
||||
return
|
||||
await get_tree().create_timer(randf_range(0.1, 2.0)).timeout
|
||||
|
||||
_on_hole_timer_timeout()
|
||||
|
||||
|
||||
@@ -129,8 +122,14 @@ func _on_hole_timer_timeout() -> void:
|
||||
var current_distractors : Array = distractions[current_progression % distractions.size()]
|
||||
holes[i].spawn_crab(current_distractors.pick_random())
|
||||
hole_found = true
|
||||
|
||||
break
|
||||
|
||||
if not hole_found:
|
||||
await get_tree().create_timer(randf_range(0.1, 0.5)).timeout
|
||||
if await _await_for_future_or_stimulus_found(get_tree().create_timer(randf_range(0.1, 0.5)).timeout):
|
||||
hole_found = true
|
||||
|
||||
|
||||
func _on_stimulus_found():
|
||||
# Despawn all the crabs
|
||||
for hole in holes:
|
||||
hole.stop.emit()
|
||||
|
||||
@@ -3,6 +3,7 @@ class_name Hole
|
||||
|
||||
signal stimulus_hit(stimulus: Dictionary)
|
||||
signal crab_despawned()
|
||||
signal stop()
|
||||
|
||||
const crab_scene: = preload("res://sources/minigames/crabs/crab/crab.tscn")
|
||||
|
||||
@@ -30,9 +31,7 @@ func spawn_crab(stimulus: Dictionary) -> void:
|
||||
# Instantiate a new crab
|
||||
crab = crab_scene.instantiate()
|
||||
mask.add_child(crab)
|
||||
|
||||
var crab_x : float = -crab.size.x / 2
|
||||
|
||||
crab.position = Vector2(crab_x, 100)
|
||||
crab.stimulus = stimulus
|
||||
|
||||
@@ -41,11 +40,14 @@ func spawn_crab(stimulus: Dictionary) -> void:
|
||||
crab_audio_stream_player.start_playing()
|
||||
var tween: = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, 20), randf_range(0.25, 2.0))
|
||||
await tween.finished
|
||||
if await is_button_pressed_with_limit(tween.finished):
|
||||
return
|
||||
crab_audio_stream_player.stop_playing()
|
||||
|
||||
# Wait a bit before going out
|
||||
timer.start(randf_range(0.25, 1.5))
|
||||
await timer.timeout
|
||||
if await is_button_pressed_with_limit(timer.timeout):
|
||||
return
|
||||
|
||||
# The crab gets completely out
|
||||
sand_vfx.stop()
|
||||
@@ -103,17 +105,34 @@ func despawn_crab() -> void:
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
|
||||
crab_despawned.emit()
|
||||
#crab_despawned.emit()
|
||||
|
||||
|
||||
func is_button_pressed_with_limit(future) -> bool:
|
||||
func is_button_pressed_with_limit(future : Signal) -> bool:
|
||||
var coroutine: = Coroutine.new()
|
||||
coroutine.add_future(crab.is_button_pressed)
|
||||
coroutine.add_future(_is_stopped)
|
||||
coroutine.add_future(future)
|
||||
await coroutine.join_either()
|
||||
|
||||
# If the crab is pressed
|
||||
if coroutine.return_value[0]:
|
||||
await _on_crab_hit(crab.stimulus)
|
||||
return true
|
||||
|
||||
# If the crab is stopped
|
||||
if coroutine.return_value[1]:
|
||||
|
||||
# Make the crab disappear in the hole
|
||||
var crab_x : float = -crab.size.x / 2
|
||||
var tween: = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, 100.0), 0.5)
|
||||
await tween.finished
|
||||
sand_vfx.play()
|
||||
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
@@ -138,3 +157,8 @@ func _on_crab_hit(stimulus: Dictionary) -> void:
|
||||
|
||||
func on_stimulus_heard(is_heard : bool):
|
||||
stimulus_heard = is_heard
|
||||
|
||||
|
||||
func _is_stopped() -> bool:
|
||||
await stop
|
||||
return true
|
||||
|
||||
@@ -15,7 +15,7 @@ layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 400.0
|
||||
offset_bottom = 400.0
|
||||
scale = Vector2(1.12849, 1.12849)
|
||||
scale = Vector2(1.07673, 1.07673)
|
||||
script = ExtResource("1_06uwq")
|
||||
|
||||
[node name="BackFX" type="Control" parent="."]
|
||||
@@ -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.678924
|
||||
frame_progress = 0.365226
|
||||
centered = false
|
||||
offset = Vector2(-0.000205994, 0.00019455)
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _highlight():
|
||||
for jellyfish: Jellyfish in spawning_space.get_children():
|
||||
if jellyfish.stimulus and jellyfish.stimulus.Grapheme == _get_current_stimulus().Grapheme:
|
||||
if jellyfish.stimulus and _is_stimulus_right(jellyfish.stimulus):
|
||||
jellyfish.highlight()
|
||||
highlight_timer.start()
|
||||
|
||||
@@ -122,10 +122,9 @@ func _get_difficulty_settings() -> DifficultySettings:
|
||||
|
||||
|
||||
func _on_current_progression_changed() -> void:
|
||||
spawn_timer.stop()
|
||||
for jellyfish: Jellyfish in spawning_space.get_children():
|
||||
jellyfish.delete()
|
||||
# Play the new stimulus
|
||||
super()
|
||||
# Restarts the spawning of jellyfishes
|
||||
spawn_timer.start()
|
||||
|
||||
|
||||
@@ -159,9 +158,9 @@ func _on_stimulus_pressed(stimulus, jellyfish: Jellyfish) -> bool:
|
||||
# Play the pressed jellyfish phoneme
|
||||
if jellyfish.stimulus and jellyfish.stimulus.Phoneme:
|
||||
await audio_player.play_phoneme(jellyfish.stimulus.Phoneme)
|
||||
|
||||
# Remove the jellyfish
|
||||
await jellyfish.delete()
|
||||
|
||||
# Remove the jellyfish
|
||||
await jellyfish.delete()
|
||||
|
||||
# Handle the blocking array
|
||||
if jellyfish in blocking_jellyfish:
|
||||
@@ -176,3 +175,10 @@ func _on_stimulus_pressed(stimulus, jellyfish: Jellyfish) -> bool:
|
||||
|
||||
func _on_highlight_timer_timeout():
|
||||
_highlight()
|
||||
|
||||
|
||||
func _on_stimulus_found():
|
||||
spawn_timer.stop()
|
||||
# Clear all the jellyfishes
|
||||
for jellyfish: Jellyfish in spawning_space.get_children():
|
||||
jellyfish.delete()
|
||||
|
||||
Reference in New Issue
Block a user