Uses pick_random for random selection in arrays.

This commit is contained in:
Dylan Sarrazyn
2024-04-08 10:08:44 +02:00
committed by BimDav
parent 643d7edab0
commit dd577277b0
9 changed files with 66 additions and 34 deletions
@@ -29,18 +29,18 @@ func _find_stimuli_and_distractions() -> void:
# If there is no previous stimuli, only adds from current lesson
if previous_lesson_stimuli.is_empty():
while stimuli.size() < max_progression:
stimuli.append(current_lesson_stimuli[randi() % current_lesson_stimuli.size()])
stimuli.append(current_lesson_stimuli.pick_random())
else:
# Calculate the number of stimuli to add from this lesson (70% of the maximum progression)
@warning_ignore("narrowing_conversion")
var number_of_stimuli: int = max_progression * stimuli_ratio
while stimuli.size() < number_of_stimuli:
stimuli.append(current_lesson_stimuli[randi() % current_lesson_stimuli.size()])
stimuli.append(current_lesson_stimuli.pick_random())
# Gets other stimuli from previous errors or lessons
# TODO Handle previous errors
while stimuli.size() < max_progression:
stimuli.append(previous_lesson_stimuli[randi() % previous_lesson_stimuli.size()])
stimuli.append(previous_lesson_stimuli.pick_random())
# Shuffle the stimuli
stimuli.shuffle()
+2 -1
View File
@@ -1,9 +1,10 @@
@tool
extends MarginContainer
extends Control
class_name Crab
signal crab_hit(stimulus: Dictionary)
@onready var body: Control = $Body
@onready var animated_sprite: = %AnimatedSprite2D
@onready var label: = %AutoSizeLabel.get_node("Label")
@onready var button: = $Button
+52 -20
View File
@@ -195,14 +195,21 @@ animations = [{
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_1h5my"]
[node name="Crab" type="MarginContainer"]
[node name="Crab" type="Control"]
custom_minimum_size = Vector2(205, 179)
layout_mode = 3
anchors_preset = 0
offset_right = 205.0
offset_bottom = 179.0
script = ExtResource("1_5hgg8")
[node name="BackFX" type="Control" parent="."]
layout_mode = 2
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="RightFX" parent="BackFX" instance=ExtResource("4_3hx0j")]
unique_name_in_owner = true
@@ -218,41 +225,61 @@ scale = Vector2(0.5, 0.5)
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="SpriteControl" type="Control" parent="." node_paths=PackedStringArray("sprites")]
layout_mode = 2
[node name="Body" type="Control" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
pivot_offset = Vector2(103, 104)
[node name="SpriteControl" type="Control" parent="Body" node_paths=PackedStringArray("sprites")]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("3_e1twq")
sprites = [NodePath("AnimatedSprite2D")]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="SpriteControl"]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Body/SpriteControl"]
unique_name_in_owner = true
position = Vector2(103, 90)
scale = Vector2(1e-05, 1e-05)
sprite_frames = SubResource("SpriteFrames_g5q5i")
animation = &"idle1"
animation = &"idle2"
autoplay = "idle1"
frame_progress = 0.302072
centered = false
offset = Vector2(-108, -90)
offset = Vector2(-5, 0)
[node name="PercentMarginContainer" type="Container" parent="."]
layout_mode = 2
[node name="PercentMarginContainer" type="Container" parent="Body"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("6_bn4pr")
margin_left_ratio = 0.2
margin_top_ratio = 0.4
margin_right_ratio = 0.2
margin_bottom_ratio = 0.3
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="PercentMarginContainer"]
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="Body/PercentMarginContainer"]
layout_mode = 2
[node name="AutoSizeLabel" parent="PercentMarginContainer/AspectRatioContainer" instance=ExtResource("7_kyqqg")]
[node name="AutoSizeLabel" parent="Body/PercentMarginContainer/AspectRatioContainer" instance=ExtResource("7_kyqqg")]
unique_name_in_owner = true
layout_mode = 2
[node name="Label" parent="PercentMarginContainer/AspectRatioContainer/AutoSizeLabel" index="0"]
text = ""
[node name="FrontFX" type="Control" parent="."]
layout_mode = 2
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="WrongFX" parent="FrontFX" instance=ExtResource("5_3sw4w")]
unique_name_in_owner = true
@@ -269,7 +296,12 @@ size_flags_horizontal = 4
size_flags_vertical = 4
[node name="Button" type="Button" parent="."]
layout_mode = 2
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/normal = SubResource("StyleBoxEmpty_tnp5x")
theme_override_styles/hover = SubResource("StyleBoxEmpty_g8ffa")
theme_override_styles/pressed = SubResource("StyleBoxEmpty_fwwak")
@@ -277,7 +309,7 @@ theme_override_styles/disabled = SubResource("StyleBoxEmpty_tdur1")
theme_override_styles/focus = SubResource("StyleBoxEmpty_1h5my")
disabled = true
[connection signal="animation_finished" from="SpriteControl/AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
[connection signal="animation_finished" from="Body/SpriteControl/AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
[editable path="PercentMarginContainer/AspectRatioContainer/AutoSizeLabel"]
[editable path="Body/PercentMarginContainer/AspectRatioContainer/AutoSizeLabel"]
+2 -2
View File
@@ -73,7 +73,7 @@ func _get_difficulty_settings() -> DifficultySettings:
# ------------ Crabs ------------
func _on_hole_stimulus_hit(stimulus: Dictionary, hole: Node2D) -> void:
func _on_hole_stimulus_hit(stimulus: Dictionary, hole: Hole) -> void:
# Logs the response
_log_new_response(stimulus, _get_current_stimulus())
@@ -110,7 +110,7 @@ func _on_hole_timer_timeout() -> void:
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()])
holes[i].spawn_crab(current_distractors.pick_random())
hole_found = true
break
+1 -1
View File
@@ -13,7 +13,7 @@
script = ExtResource("2_gierf")
difficulty = 2
minigame_name = "Crabs"
lesson_nb = 30
lesson_nb = 10
difficulty = 4
lesson_nb = 3
max_number_of_lives = 5
+1 -2
View File
@@ -97,8 +97,7 @@ func _on_crab_hit(stimulus: Dictionary) -> void:
# Move the crab up and rotate
var tween: = create_tween()
tween.tween_property(crab, "position", Vector2(crab_x, -180), 0.5)
# TODO FIX
tween.parallel().tween_property(crab.animated_sprite, "rotation_degrees", 540.0, 0.5)
tween.parallel().tween_property(crab.body, "rotation_degrees", 540.0, 0.5)
await tween.finished
# Make the crab disappear in the hole
-1
View File
@@ -9,7 +9,6 @@
[ext_resource type="Script" path="res://sources/minigames/crabs/hole/hole_audio_stream_player_2d.gd" id="6_2rg3s"]
[node name="Hole" type="Node2D"]
position = Vector2(947, 568)
scale = Vector2(1.8, 1.8)
script = ExtResource("1_05s8c")
+4 -3
View File
@@ -6,15 +6,16 @@
[ext_resource type="PackedScene" uid="uid://cge0uyn30tcpv" path="res://sources/utils/fx/highlight.tscn" id="3_5uhvd"]
[ext_resource type="Script" path="res://sources/utils/percent_margin_container.gd" id="3_vllju"]
[ext_resource type="PackedScene" uid="uid://c6klih3h3ws6f" path="res://sources/utils/auto_size_label.tscn" id="4_26xiq"]
[ext_resource type="SpriteFrames" uid="uid://dquynn3nx52o" path="res://sources/minigames/jellyfish/red_jellyfish_animations.tres" id="5_74hi7"]
[ext_resource type="SpriteFrames" uid="uid://dkemftb4jdxvs" path="res://sources/minigames/jellyfish/green_jellyfish_animations.tres" id="5_cbptq"]
[ext_resource type="PackedScene" uid="uid://dlmbxcgiv8tpr" path="res://sources/utils/fx/wrong.tscn" id="6_w1tlu"]
[node name="Jellyfish" type="MarginContainer"]
custom_minimum_size = Vector2(400, 400)
offset_right = 400.0
offset_bottom = 400.0
scale = Vector2(1.1298, 1.1298)
scale = Vector2(1.49766, 1.49766)
script = ExtResource("1_06uwq")
color = 1
[node name="BackFX" type="Control" parent="."]
custom_minimum_size = Vector2(0, 220)
@@ -56,7 +57,7 @@ sprites = [NodePath("AnimatedSprite2D")]
unique_name_in_owner = true
position = Vector2(200.8, 109.84)
scale = Vector2(1e-05, 1e-05)
sprite_frames = ExtResource("5_74hi7")
sprite_frames = ExtResource("5_cbptq")
animation = &"idle"
centered = false
offset = Vector2(-93.3722, -51.0754)
@@ -83,7 +83,7 @@ func _spawn() -> void:
new_jellyfish.stimulus = _get_current_stimulus()
else:
var current_distractors : Array = distractions[current_progression % distractions.size()]
new_jellyfish.stimulus = current_distractors[randi() % current_distractors.size()]
new_jellyfish.stimulus = current_distractors.pick_random()
# Randomize the spawn and adds the jellyfish into the scene
var random_spawn: = randi_range(0, permitted_range - 1)