Makes the crabs minigame extends HearAndFindMinigame. Fixes the distractors for the crabs minigame.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
extends Minigame
|
||||
class_name HearAndFindMinigame
|
||||
|
||||
# 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:
|
||||
var current_lesson_stimuli = []
|
||||
var previous_lesson_stimuli = []
|
||||
@@ -82,14 +84,40 @@ func _find_stimuli_and_distractions() -> void:
|
||||
distractions.append(stimulus_distractors)
|
||||
|
||||
|
||||
func _get_current_stimulus() -> Dictionary :
|
||||
# Get the current stimulus which needs to be found to increase progression
|
||||
func _get_current_stimulus() -> Dictionary:
|
||||
if stimuli.size() == 0:
|
||||
return {}
|
||||
return stimuli[current_progression % stimuli.size()]
|
||||
|
||||
|
||||
# Verify if the provided stimulus is right, if it has the same grapheme as the current stimulus
|
||||
func _is_stimulus_right(stimulus : Dictionary) -> bool:
|
||||
if not stimulus or not stimulus.has("Grapheme"):
|
||||
return false
|
||||
|
||||
var current_stimulus := _get_current_stimulus()
|
||||
if not current_stimulus or not current_stimulus.has("Grapheme"):
|
||||
return false
|
||||
|
||||
return stimulus.Grapheme == current_stimulus.Grapheme
|
||||
|
||||
|
||||
# Play the phoneme of the current stimulus
|
||||
func _play_current_stimulus_phoneme() -> void:
|
||||
var current_stimulus: = _get_current_stimulus()
|
||||
if not current_stimulus or not current_stimulus.has("Phoneme"):
|
||||
return
|
||||
await audio_player.play_phoneme(current_stimulus.Phoneme)
|
||||
|
||||
|
||||
# ------------ UI Callbacks ------------
|
||||
|
||||
|
||||
func _on_current_progression_changed() -> void:
|
||||
if current_progression > 0:
|
||||
_play_current_stimulus_phoneme()
|
||||
|
||||
|
||||
func _play_stimulus() -> void:
|
||||
await _play_current_stimulus_phoneme()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
extends Node2D
|
||||
|
||||
const instance_scene: = "res://sources/minigames/crabs/crab/crab.tscn"
|
||||
class_name Crab
|
||||
|
||||
signal crab_hit(stimulus: Dictionary)
|
||||
|
||||
@@ -10,21 +9,19 @@ signal crab_hit(stimulus: Dictionary)
|
||||
@onready var right_fx: = $RightFX
|
||||
@onready var wrong_fx: = $WrongFX
|
||||
|
||||
|
||||
var stimulus: Dictionary:
|
||||
set = _set_stimulus
|
||||
|
||||
|
||||
static func instantiate() -> Node2D:
|
||||
return load(instance_scene).instantiate()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_button_active(false)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
right_fx.global_rotation = 0.0
|
||||
wrong_fx.global_rotation = 0.0
|
||||
# right_fx.global_rotation = 0.0
|
||||
# wrong_fx.global_rotation = 0.0
|
||||
pass
|
||||
|
||||
|
||||
func set_button_active(active: bool) -> void:
|
||||
@@ -48,7 +45,8 @@ func wrong() -> void:
|
||||
|
||||
func _set_stimulus(value: Dictionary) -> void:
|
||||
stimulus = value
|
||||
label.text = stimulus["Grapheme"]
|
||||
if stimulus.has("Grapheme"):
|
||||
label.text = stimulus.Grapheme
|
||||
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
|
||||
@@ -112,6 +112,9 @@ font_size = 42
|
||||
[node name="Crab" type="Node2D"]
|
||||
script = ExtResource("1_5hgg8")
|
||||
|
||||
[node name="RightFX" parent="." instance=ExtResource("4_3hx0j")]
|
||||
scale = Vector2(0.5, 0.5)
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_ifo73")
|
||||
@@ -146,9 +149,6 @@ theme_override_styles/pressed = SubResource("StyleBoxEmpty_fwwak")
|
||||
theme_override_styles/disabled = SubResource("StyleBoxEmpty_tdur1")
|
||||
theme_override_styles/focus = SubResource("StyleBoxEmpty_1h5my")
|
||||
|
||||
[node name="RightFX" parent="." instance=ExtResource("4_3hx0j")]
|
||||
scale = Vector2(0.5, 0.5)
|
||||
|
||||
[node name="WrongFX" parent="." instance=ExtResource("5_3sw4w")]
|
||||
scale = Vector2(0.5, 0.5)
|
||||
|
||||
|
||||
@@ -1,105 +1,101 @@
|
||||
@tool
|
||||
extends Minigame
|
||||
extends HearAndFindMinigame
|
||||
|
||||
const hole_class: = preload("res://sources/minigames/crabs/hole/hole.tscn")
|
||||
const difficulty_settings: = {
|
||||
0: {"crab_rows": [2, 1]},
|
||||
1 : {"crab_rows": [3, 2]},
|
||||
2 : {"crab_rows": [4, 3]},
|
||||
3 : {"crab_rows": [4, 3, 2]},
|
||||
4 : {"crab_rows": [4, 3, 4]},
|
||||
}
|
||||
const hole_scene: = preload("res://sources/minigames/crabs/hole/hole.tscn")
|
||||
|
||||
class DifficultySettings:
|
||||
var stimuli_ratio: = 0.75
|
||||
var rows: = [2, 1]
|
||||
|
||||
func _init(p_stimuli_ratio: float, p_rows: Array[int]) -> void:
|
||||
stimuli_ratio = p_stimuli_ratio
|
||||
rows = p_rows
|
||||
|
||||
var difficulty_settings: Array[DifficultySettings] = [
|
||||
DifficultySettings.new(0.75, [2, 1]),
|
||||
DifficultySettings.new(0.66, [3, 2]),
|
||||
DifficultySettings.new(0.33, [4, 3]),
|
||||
DifficultySettings.new(0.25, [4, 3, 2]),
|
||||
DifficultySettings.new(0.25, [4, 3, 4])
|
||||
]
|
||||
|
||||
@onready var crab_zone: = $GameRoot/CrabZone
|
||||
|
||||
var holes: = []
|
||||
var holes: Array[Hole] = []
|
||||
|
||||
|
||||
# ------------ Initialisation ------------
|
||||
|
||||
|
||||
# Find and set the parameters of the minigame, like the number of lives or the victory conditions.
|
||||
func _setup_minigame() -> void:
|
||||
super._setup_minigame()
|
||||
|
||||
# Progression management
|
||||
current_progression = 0
|
||||
var settings: = _get_difficulty_settings()
|
||||
|
||||
var max_difficulty: = 0
|
||||
for d in difficulty_settings.keys():
|
||||
if d > max_difficulty:
|
||||
max_difficulty = d
|
||||
|
||||
if difficulty > max_difficulty:
|
||||
difficulty = max_difficulty
|
||||
|
||||
var settings: Dictionary = difficulty_settings[difficulty]
|
||||
# Spawns the good amount of holes and places them
|
||||
var top_left: Vector2 = crab_zone.position
|
||||
var bottom_right: Vector2 = top_left + crab_zone.size
|
||||
for i in range(settings["crab_rows"].size()):
|
||||
var fi: = float(i + 1.0) / float(settings["crab_rows"].size() + 1.0)
|
||||
for i in range(settings.rows.size()):
|
||||
var fi: = float(i + 1.0) / float(settings.rows.size() + 1.0)
|
||||
var y: float = (1.0 - fi) * top_left.y + fi * bottom_right.y
|
||||
for j in range(settings["crab_rows"][i]):
|
||||
var fj: = float(j + 1.0) / float(settings["crab_rows"][i] + 1.0)
|
||||
for j in range(settings.rows[i]):
|
||||
var fj: = float(j + 1.0) / float(settings.rows[i] + 1.0)
|
||||
var x: float = fj * top_left.x + (1.0 - fj) * bottom_right.x
|
||||
|
||||
var hole: = hole_class.instantiate()
|
||||
var hole: Hole = hole_scene.instantiate()
|
||||
game_root.add_child(hole)
|
||||
hole.position = Vector2(x, y)
|
||||
|
||||
hole.stimulus_hit.connect(_on_hole_stimulus_hit.bind(hole))
|
||||
hole.crab_despawned.connect(_on_hole_crab_despawned)
|
||||
if not Engine.is_editor_hint():
|
||||
hole.stimulus_hit.connect(_on_hole_stimulus_hit.bind(hole))
|
||||
hole.crab_despawned.connect(_on_hole_crab_despawned)
|
||||
|
||||
holes.append(hole)
|
||||
|
||||
|
||||
func _find_stimuli_and_distractions() -> void:
|
||||
stimuli = Database.get_GP_for_lesson(lesson_nb, true)
|
||||
var all_distractions: = Database.get_GP_before_lesson(lesson_nb, true)
|
||||
all_distractions.shuffle()
|
||||
|
||||
var number_of_distractions: int = min((max_progression - 1) / 2, all_distractions.size())
|
||||
var current_distractions: = all_distractions.slice(0, number_of_distractions)
|
||||
|
||||
stimuli.append_array(current_distractions)
|
||||
distractions = stimuli.duplicate()
|
||||
|
||||
|
||||
# Launch the minigame
|
||||
func _start() -> void:
|
||||
super()
|
||||
|
||||
_on_hole_timer_timeout(stimuli[current_progression % stimuli.size()])
|
||||
audio_player.stream = Database.get_audio_stream_for_phoneme(stimuli[current_progression % stimuli.size()].Phoneme)
|
||||
audio_player.play()
|
||||
_play_current_stimulus_phoneme()
|
||||
|
||||
for i in range(int(3.0 * holes.size() / 4.0)):
|
||||
_on_hole_crab_despawned(stimuli[randi() % stimuli.size()])
|
||||
|
||||
_on_hole_crab_despawned()
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
|
||||
|
||||
func _get_difficulty_settings() -> DifficultySettings:
|
||||
return difficulty_settings[difficulty]
|
||||
|
||||
|
||||
# ------------ Crabs ------------
|
||||
|
||||
|
||||
func _on_hole_stimulus_hit(stimulus: Dictionary, hole: Node2D) -> void:
|
||||
_log_new_response(stimulus, stimuli[current_progression % stimuli.size()])
|
||||
if stimulus == stimuli[current_progression % stimuli.size()]:
|
||||
# Logs the response
|
||||
_log_new_response(stimulus, _get_current_stimulus())
|
||||
|
||||
var is_right: = _is_stimulus_right(stimulus)
|
||||
if is_right:
|
||||
hole.right()
|
||||
current_progression += 1
|
||||
else:
|
||||
audio_player.stream = Database.get_audio_stream_for_phoneme(stimulus.Phoneme)
|
||||
audio_player.play()
|
||||
hole.wrong()
|
||||
current_lives -= 1
|
||||
|
||||
# Play the pressed crab phoneme
|
||||
if stimulus and stimulus.Phoneme:
|
||||
await audio_player.play_phoneme(stimulus.Phoneme)
|
||||
|
||||
|
||||
func _on_hole_crab_despawned(stimulus: Dictionary) -> void:
|
||||
func _on_hole_crab_despawned() -> void:
|
||||
await get_tree().create_timer(randf_range(0.1, 2.0)).timeout
|
||||
|
||||
_on_hole_timer_timeout(stimulus)
|
||||
_on_hole_timer_timeout()
|
||||
|
||||
|
||||
func _on_hole_timer_timeout(_stimulus: Dictionary) -> void:
|
||||
func _on_hole_timer_timeout() -> void:
|
||||
var holes_range: = range(holes.size())
|
||||
holes_range.shuffle()
|
||||
|
||||
@@ -107,23 +103,16 @@ func _on_hole_timer_timeout(_stimulus: Dictionary) -> void:
|
||||
while not hole_found:
|
||||
for i in holes_range:
|
||||
if not holes[i].crab:
|
||||
holes[i].spawn_crab(stimuli[randi() % stimuli.size()])
|
||||
# Define if the crab is a stimulus or a distraction
|
||||
var is_stimulus: = randf() < _get_difficulty_settings().stimuli_ratio
|
||||
if is_stimulus:
|
||||
holes[i].spawn_crab(_get_current_stimulus())
|
||||
else:
|
||||
var current_distractors : Array = distractions[current_progression % distractions.size()]
|
||||
holes[i].spawn_crab(current_distractors[randi() % current_distractors.size()])
|
||||
hole_found = true
|
||||
|
||||
break
|
||||
|
||||
if not hole_found:
|
||||
await get_tree().create_timer(randf_range(0.1, 0.5)).timeout
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
func _play_stimulus() -> void:
|
||||
audio_player.stream = Database.get_audio_stream_for_phoneme(stimuli[current_progression % stimuli.size()].Phoneme)
|
||||
audio_player.play()
|
||||
if audio_player.playing:
|
||||
await audio_player.finished
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://bxh1torc05k7p"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://8awe4usnucyv" path="res://sources/minigames/base/base_minigame.tscn" id="1_lbq56"]
|
||||
[ext_resource type="PackedScene" uid="uid://clbi7qphyh0so" path="res://sources/minigames/base/hear_and_find/hear_and_find_minigame.tscn" id="1_lbq56"]
|
||||
[ext_resource type="Script" path="res://sources/minigames/crabs/crabs_minigame.gd" id="2_gierf"]
|
||||
[ext_resource type="AudioStream" uid="uid://4qo683e8atp4" path="res://language_resources/pt/minigames/crabs/audio/kalulu/kalulu_help_crabs_language.mp3" id="3_8pn05"]
|
||||
[ext_resource type="AudioStream" uid="uid://c2qmghbq5c2x6" path="res://language_resources/fr/minigames/crabs/audio/kalulu/kalulu_intro_crabs_language.mp3" id="3_shwct"]
|
||||
@@ -9,10 +9,11 @@
|
||||
[ext_resource type="Texture2D" uid="uid://cq5wwf7y1msh7" path="res://assets/minigames/crabs/graphic/gauge_icon_crab_full.png" id="6_1r44u"]
|
||||
[ext_resource type="Texture2D" uid="uid://5bx8ugh178j1" path="res://assets/minigames/crabs/graphic/background.png" id="7_s0cgt"]
|
||||
|
||||
[node name="Crabs" instance=ExtResource("1_lbq56")]
|
||||
[node name="CrabsMinigame" instance=ExtResource("1_lbq56")]
|
||||
script = ExtResource("2_gierf")
|
||||
difficulty = 2
|
||||
minigame_name = "Crabs"
|
||||
difficulty = 4
|
||||
lesson_nb = 3
|
||||
max_number_of_lives = 5
|
||||
max_progression = 5
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
extends Node2D
|
||||
class_name Hole
|
||||
|
||||
signal stimulus_hit(stimulus: Dictionary)
|
||||
signal crab_despawned(stimulus: Dictionary)
|
||||
signal crab_despawned()
|
||||
|
||||
const Crab: = preload("res://sources/minigames/crabs/crab/crab.gd")
|
||||
const crab_scene: = preload("res://sources/minigames/crabs/crab/crab.tscn")
|
||||
|
||||
@onready var hole_back: = $HoleBack
|
||||
@onready var hole_front: = $HoleFront
|
||||
@@ -15,7 +16,7 @@ var crab: Crab
|
||||
|
||||
|
||||
func spawn_crab(stimulus: Dictionary) -> void:
|
||||
crab = Crab.instantiate()
|
||||
crab = crab_scene.instantiate()
|
||||
mask.add_child(crab)
|
||||
|
||||
crab.position = Vector2(0, 200)
|
||||
@@ -61,7 +62,7 @@ func spawn_crab(stimulus: Dictionary) -> void:
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
|
||||
crab_despawned.emit(stimulus)
|
||||
crab_despawned.emit()
|
||||
|
||||
|
||||
func is_button_pressed_with_limit(future):
|
||||
@@ -99,4 +100,4 @@ func _on_crab_hit(stimulus: Dictionary) -> void:
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
|
||||
crab_despawned.emit(stimulus)
|
||||
crab_despawned.emit()
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
custom_minimum_size = Vector2(400, 400)
|
||||
offset_right = 400.0
|
||||
offset_bottom = 400.0
|
||||
scale = Vector2(1.08314, 1.08314)
|
||||
scale = Vector2(1.19098, 1.19098)
|
||||
script = ExtResource("1_06uwq")
|
||||
|
||||
[node name="BackFX" type="Control" parent="."]
|
||||
|
||||
@@ -12,13 +12,13 @@ class DifficultySettings:
|
||||
stimuli_ratio = p_stimuli_ratio
|
||||
velocity = p_velocity
|
||||
|
||||
var difficulty_settings: = {
|
||||
0: DifficultySettings.new(4, 0.75, 150),
|
||||
1: DifficultySettings.new(3, 0.66, 175),
|
||||
2: DifficultySettings.new(2, 0.33, 200),
|
||||
3: DifficultySettings.new(1, 0.25, 250),
|
||||
4: DifficultySettings.new(1, 0.25, 300),
|
||||
}
|
||||
var difficulty_settings: Array[DifficultySettings] = [
|
||||
DifficultySettings.new(4, 0.75, 150),
|
||||
DifficultySettings.new(3, 0.66, 175),
|
||||
DifficultySettings.new(2, 0.33, 200),
|
||||
DifficultySettings.new(1, 0.25, 250),
|
||||
DifficultySettings.new(1, 0.25, 300)
|
||||
]
|
||||
|
||||
var blocking_jellyfish: Array[Jellyfish] = []
|
||||
|
||||
@@ -138,7 +138,7 @@ func _on_jellyfish_pressed(jellyfish: Jellyfish) -> void:
|
||||
_log_new_response(jellyfish.stimulus, _get_current_stimulus())
|
||||
|
||||
# Check if the stimulus is right
|
||||
var is_right: bool = jellyfish.stimulus.Grapheme == _get_current_stimulus().Grapheme
|
||||
var is_right: = _is_stimulus_right(jellyfish.stimulus)
|
||||
if is_right:
|
||||
jellyfish.happy()
|
||||
jellyfish.right()
|
||||
@@ -167,15 +167,3 @@ func _on_jellyfish_pressed(jellyfish: Jellyfish) -> void:
|
||||
|
||||
func _on_highlight_timer_timeout():
|
||||
_highlight()
|
||||
|
||||
|
||||
# ------------ UI Callbacks ------------
|
||||
|
||||
|
||||
func _on_current_progression_changed() -> void:
|
||||
if current_progression > 0:
|
||||
_play_current_stimulus_phoneme()
|
||||
|
||||
|
||||
func _play_stimulus() -> void:
|
||||
await _play_current_stimulus_phoneme()
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
[node name="JellyfishMinigame" instance=ExtResource("1_hauef")]
|
||||
script = ExtResource("2_gnjlp")
|
||||
lesson_nb = 6
|
||||
difficulty = 1
|
||||
difficulty = 4
|
||||
intro_kalulu_speech = ExtResource("3_6sswr")
|
||||
help_kalulu_speech = ExtResource("2_7li38")
|
||||
win_kalulu_speech = ExtResource("3_ar7nu")
|
||||
|
||||
Reference in New Issue
Block a user