Add join_either and audio stimuli in crabs
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
extends Node2D
|
||||
class_name Crab
|
||||
|
||||
const instance_scene: = "res://sources/minigames/crabs/crab/crab.tscn"
|
||||
|
||||
signal crab_hit(stimulus: Dictionary)
|
||||
|
||||
@@ -7,7 +8,10 @@ signal crab_hit(stimulus: Dictionary)
|
||||
@onready var label: = $Label
|
||||
@onready var button: = $Button
|
||||
|
||||
var stimulus: Dictionary
|
||||
var stimulus: Dictionary:
|
||||
set(p_stimulus):
|
||||
stimulus = p_stimulus
|
||||
label.text = stimulus["Grapheme"]
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -18,21 +22,24 @@ func set_button_active(active: bool) -> void:
|
||||
button.disabled = not active
|
||||
|
||||
|
||||
func set_stimulus(p_stimulus: Dictionary) -> void:
|
||||
stimulus = p_stimulus
|
||||
|
||||
label.text = stimulus["Grapheme"]
|
||||
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
emit_signal("crab_hit", stimulus)
|
||||
crab_hit.emit(stimulus)
|
||||
animation_player.play("hit")
|
||||
|
||||
|
||||
func is_button_pressed() -> bool:
|
||||
await button.pressed
|
||||
return true
|
||||
|
||||
|
||||
func _on_animation_player_animation_finished(animation_name: StringName) -> void:
|
||||
var idles: = ["idle1", "idle2"]
|
||||
if animation_name in idles:
|
||||
var r: = randi() % idles.size()
|
||||
animation_player.play(idles[r])
|
||||
if animation_name == "hit":
|
||||
elif animation_name == "hit":
|
||||
animation_player.play("hurt")
|
||||
|
||||
|
||||
static func instantiate() -> Node2D:
|
||||
return load(instance_scene).instantiate()
|
||||
|
||||
@@ -66,6 +66,8 @@ func _start() -> void:
|
||||
super()
|
||||
|
||||
_on_hole_timer_timeout(stimuli[0])
|
||||
audio_player.stream = Database.get_audio_stream_for_phoneme(stimuli[0].Phoneme)
|
||||
audio_player.play()
|
||||
|
||||
for i in range(int(3.0 * holes.size() / 4.0)):
|
||||
_on_hole_crab_despawned(distractions[randi() % distractions.size()])
|
||||
@@ -81,6 +83,8 @@ func _on_hole_stimulus_hit(stimulus: Dictionary) -> void:
|
||||
current_progression += 1
|
||||
else:
|
||||
current_lives -= 1
|
||||
audio_player.stream = Database.get_audio_stream_for_phoneme(stimulus.Phoneme)
|
||||
audio_player.play()
|
||||
|
||||
|
||||
func _on_hole_timer_timeout(stimulus: Dictionary) -> void:
|
||||
@@ -90,7 +94,7 @@ func _on_hole_timer_timeout(stimulus: Dictionary) -> void:
|
||||
var hole_found: = false
|
||||
while not hole_found:
|
||||
for i in holes_range:
|
||||
if not holes[i].crab_spawned:
|
||||
if not holes[i].crab:
|
||||
holes[i].spawn_crab(stimulus)
|
||||
hole_found = true
|
||||
|
||||
@@ -104,3 +108,9 @@ func _on_hole_crab_despawned(stimulus: Dictionary) -> void:
|
||||
await get_tree().create_timer(randf_range(0.1, 2.0)).timeout
|
||||
|
||||
_on_hole_timer_timeout(stimulus)
|
||||
|
||||
|
||||
func _on_current_progression_changed() -> void:
|
||||
if current_progression > 0:
|
||||
audio_player.stream = Database.get_audio_stream_for_phoneme(stimuli[current_progression % stimuli.size()].Phoneme)
|
||||
audio_player.play()
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
[node name="Crabs" instance=ExtResource("1_lbq56")]
|
||||
script = ExtResource("2_gierf")
|
||||
difficulty = 4
|
||||
lesson_nb = 4
|
||||
lesson_nb = 3
|
||||
minigame_name = "Crabs"
|
||||
max_number_of_lives = 5
|
||||
max_progression = 5
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
extends Node2D
|
||||
class_name CrabHole
|
||||
|
||||
signal stimulus_hit(stimulus: Dictionary)
|
||||
signal crab_despawned(stimulus: Dictionary)
|
||||
|
||||
const crab_class: = preload("res://sources/minigames/crabs/crab/crab.tscn")
|
||||
const Crab: = preload("res://sources/minigames/crabs/crab/crab.gd")
|
||||
|
||||
@onready var hole_back: = $HoleBack
|
||||
@onready var hole_front: = $HoleFront
|
||||
@@ -13,27 +12,21 @@ const crab_class: = preload("res://sources/minigames/crabs/crab/crab.tscn")
|
||||
@onready var crab_audio_stream_player: = $CrabAudioStreamPlayer2D
|
||||
|
||||
var crab: Crab
|
||||
var crab_hit: = false
|
||||
var crab_spawned: = false
|
||||
|
||||
|
||||
func spawn_crab(stimulus: Dictionary) -> void:
|
||||
crab_spawned = true
|
||||
|
||||
crab = crab_class.instantiate()
|
||||
crab = Crab.instantiate()
|
||||
mask.add_child(crab)
|
||||
|
||||
crab.connect("crab_hit", _crab_hit)
|
||||
|
||||
crab.position = Vector2(0, 200)
|
||||
crab.set_stimulus(stimulus)
|
||||
crab.stimulus = stimulus
|
||||
|
||||
crab_audio_stream_player.start_playing()
|
||||
|
||||
var first_tween: = create_tween()
|
||||
first_tween.tween_property(crab, "position", Vector2(0.0, 100.0), randf_range(0.25, 2.0))
|
||||
await first_tween.finished
|
||||
first_tween.kill()
|
||||
# Show the crab but not the stimulus
|
||||
var tween: = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(0.0, 100.0), randf_range(0.25, 2.0))
|
||||
await tween.finished
|
||||
|
||||
crab_audio_stream_player.stop_playing()
|
||||
|
||||
@@ -42,42 +35,57 @@ func spawn_crab(stimulus: Dictionary) -> void:
|
||||
|
||||
crab_audio_stream_player.start_playing()
|
||||
|
||||
var second_tween: = create_tween()
|
||||
second_tween.tween_property(crab, "position", Vector2(0.0, -50.0), 0.25)
|
||||
await second_tween.finished
|
||||
second_tween.kill()
|
||||
# The crab gets completely out
|
||||
tween = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(0.0, -50.0), 0.5)
|
||||
crab.set_button_active(true)
|
||||
if await is_button_pressed_with_limit(tween.finished):
|
||||
return
|
||||
|
||||
crab_audio_stream_player.stop_playing()
|
||||
|
||||
crab_hit = false
|
||||
crab.set_button_active(true)
|
||||
|
||||
timer.start(randf_range(1.0, 2.5))
|
||||
await timer.timeout
|
||||
if await is_button_pressed_with_limit(timer.timeout):
|
||||
return
|
||||
|
||||
crab_audio_stream_player.start_playing()
|
||||
tween = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(0.0, 200.0), 0.5)
|
||||
if await is_button_pressed_with_limit(tween.finished):
|
||||
return
|
||||
|
||||
crab.set_button_active(false)
|
||||
|
||||
var final_tween: = create_tween()
|
||||
if crab_hit:
|
||||
final_tween.tween_property(crab, "position", Vector2(0.0, -200.0), 0.5)
|
||||
final_tween.parallel().tween_property(crab, "rotation_degrees", 540.0, 0.5)
|
||||
else:
|
||||
crab_audio_stream_player.start_playing()
|
||||
final_tween.tween_property(crab, "position", Vector2(0.0, 200.0), 0.25)
|
||||
await final_tween.finished
|
||||
|
||||
crab_audio_stream_player.stop_playing()
|
||||
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
|
||||
crab_spawned = false
|
||||
|
||||
emit_signal("crab_despawned", stimulus)
|
||||
crab_despawned.emit(stimulus)
|
||||
|
||||
|
||||
func _crab_hit(stimulus: Dictionary) -> void:
|
||||
crab_hit = true
|
||||
func _on_crab_hit(stimulus: Dictionary) -> void:
|
||||
var tween: = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(0.0, -200.0), 0.5)
|
||||
tween.parallel().tween_property(crab, "rotation_degrees", 540.0, 0.5)
|
||||
await tween.finished
|
||||
crab.set_button_active(false)
|
||||
if not timer.is_stopped():
|
||||
timer.start(0.4)
|
||||
emit_signal("stimulus_hit", stimulus)
|
||||
stimulus_hit.emit(stimulus)
|
||||
crab_audio_stream_player.stop_playing()
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
|
||||
crab_despawned.emit(stimulus)
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
|
||||
[node name="Parakeets" instance=ExtResource("1_oeg4r")]
|
||||
script = ExtResource("2_x6xn5")
|
||||
difficulty = 4
|
||||
lesson_nb = 4
|
||||
fly_duration = 3.0
|
||||
max_number_of_lives = 5
|
||||
help_kalulu_speech = ExtResource("3_ofxb4")
|
||||
win_kalulu_speech = ExtResource("4_01e28")
|
||||
difficulty = 4
|
||||
lesson_nb = 4
|
||||
fly_duration = 3.0
|
||||
|
||||
[node name="Background" type="TextureRect" parent="GameRoot" index="0"]
|
||||
layout_mode = 1
|
||||
|
||||
Reference in New Issue
Block a user