Change Minigame to Control, fix setters
This commit is contained in:
@@ -1,13 +1,21 @@
|
||||
extends Node2D
|
||||
@tool
|
||||
extends Control
|
||||
class_name Minigame
|
||||
|
||||
@export var minigame_name: = "Minigame"
|
||||
|
||||
@export var max_number_of_lives: = 0 :
|
||||
set(value): _set_max_lives(value)
|
||||
get: return _max_number_of_lives
|
||||
set(value):
|
||||
max_number_of_lives = value
|
||||
if minigame_ui:
|
||||
minigame_ui.set_maximum_number_of_lives(value)
|
||||
|
||||
@export var max_progression: = 0 :
|
||||
set(value): _set_max_progression(value)
|
||||
get: return _max_progression
|
||||
set(value):
|
||||
max_progression = value
|
||||
if minigame_ui:
|
||||
minigame_ui.set_max_progression(value)
|
||||
|
||||
@export var help_kalulu_speech: AudioStream
|
||||
@export var win_kalulu_speech: AudioStream
|
||||
@export var lose_kalulu_speech: AudioStream = preload("res://resources/minigames/kalulu/kalulu_lose_minigame_all.mp3")
|
||||
@@ -32,18 +40,22 @@ var stimuli: = []
|
||||
var distractions: = []
|
||||
|
||||
# Lives
|
||||
var _max_number_of_lives : = 0
|
||||
var current_lives: = 0 :
|
||||
set(value): _set_current_lives(value)
|
||||
get: return _current_lives
|
||||
var _current_lives: = 0
|
||||
set(value):
|
||||
if value == 0 and current_lives != 0:
|
||||
_lose()
|
||||
current_lives = value
|
||||
if minigame_ui:
|
||||
minigame_ui.set_number_of_lives(value)
|
||||
|
||||
# Progression
|
||||
var _max_progression: = 0
|
||||
var current_progression: = 0 :
|
||||
set(value): _set_current_progression(value)
|
||||
get: return _current_progression
|
||||
var _current_progression: = 0
|
||||
set(value):
|
||||
if value == max_progression and current_progression != max_progression:
|
||||
_win()
|
||||
current_progression = value
|
||||
if minigame_ui:
|
||||
minigame_ui.set_current_progression(value)
|
||||
|
||||
|
||||
# ------------ Initialisation ------------
|
||||
@@ -58,7 +70,8 @@ func _initialize() -> void:
|
||||
|
||||
_find_stimuli_and_distractions()
|
||||
|
||||
_start()
|
||||
if not Engine.is_editor_hint():
|
||||
_start()
|
||||
|
||||
|
||||
# Find and set the parameters of the minigame, like the number of lives or the victory conditions.
|
||||
@@ -167,34 +180,3 @@ func _on_minigame_ui_kalulu_button_pressed() -> void:
|
||||
|
||||
func _on_minigame_ui_restart_button_pressed() -> void:
|
||||
_reset()
|
||||
|
||||
|
||||
# ------------ setters/getters ------------
|
||||
|
||||
|
||||
func _set_max_lives(value: int) -> void:
|
||||
_max_number_of_lives = value
|
||||
if minigame_ui:
|
||||
minigame_ui.set_maximum_number_of_lives(value)
|
||||
|
||||
|
||||
func _set_current_lives(value: int) -> void:
|
||||
_current_lives = value
|
||||
if minigame_ui:
|
||||
minigame_ui.set_number_of_lives(value)
|
||||
if current_lives == 0:
|
||||
_lose()
|
||||
|
||||
|
||||
func _set_max_progression(value: int) -> void:
|
||||
_max_progression = value
|
||||
if minigame_ui:
|
||||
minigame_ui.set_max_progression(value)
|
||||
|
||||
|
||||
func _set_current_progression(value: int) -> void:
|
||||
_current_progression = value
|
||||
if minigame_ui:
|
||||
minigame_ui.set_current_progression(value)
|
||||
if current_progression == max_progression:
|
||||
_win()
|
||||
|
||||
@@ -4,8 +4,14 @@
|
||||
[ext_resource type="PackedScene" uid="uid://weree6bnlt6f" path="res://sources/minigames/base/minigame_ui.tscn" id="2_a3tib"]
|
||||
[ext_resource type="PackedScene" uid="uid://b3ckdfnbc7077" path="res://sources/minigames/base/opening_curtain.tscn" id="3_p5ryr"]
|
||||
|
||||
[node name="BaseMinigame" type="Node2D"]
|
||||
[node name="BaseMinigame" type="Control"]
|
||||
process_mode = 3
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_jdfsm")
|
||||
|
||||
[node name="MinigameUI" parent="." instance=ExtResource("2_a3tib")]
|
||||
@@ -15,12 +21,12 @@ script = ExtResource("1_jdfsm")
|
||||
[node name="StimuliFinder" type="Node" parent="."]
|
||||
process_mode = 3
|
||||
|
||||
[node name="GameRoot" type="Node2D" parent="."]
|
||||
[node name="GameRoot" type="Control" parent="."]
|
||||
process_mode = 1
|
||||
anchors_preset = 0
|
||||
|
||||
[connection signal="garden_button_pressed" from="MinigameUI" to="." method="_on_minigame_ui_garden_button_pressed"]
|
||||
[connection signal="kalulu_button_pressed" from="MinigameUI" to="." method="_on_minigame_ui_kalulu_button_pressed"]
|
||||
[connection signal="kalulu_speech_end" from="MinigameUI" to="." method="_on_minigame_ui_kalulu_speech_end"]
|
||||
[connection signal="pause_button_pressed" from="MinigameUI" to="." method="_on_minigame_ui_pause_button_pressed"]
|
||||
[connection signal="restart_button_pressed" from="MinigameUI" to="." method="_on_minigame_ui_restart_button_pressed"]
|
||||
[connection signal="stimulus_button_pressed" from="MinigameUI" to="." method="_on_minigame_ui_stimulus_button_pressed"]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@tool
|
||||
extends CanvasLayer
|
||||
class_name MinigameUI
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=26 format=3 uid="uid://weree6bnlt6f"]
|
||||
[gd_scene load_steps=24 format=3 uid="uid://weree6bnlt6f"]
|
||||
|
||||
[ext_resource type="Script" path="res://sources/minigames/base/minigame_ui.gd" id="1_g5fl4"]
|
||||
[ext_resource type="Texture2D" uid="uid://dj0ygi5q6kbdw" path="res://resources/minigames/minigame_ui/graphic/button_back_to_menu_up.png" id="2_0d0qn"]
|
||||
@@ -20,10 +20,8 @@
|
||||
[ext_resource type="Texture2D" uid="uid://dqtmyedk1ylbw" path="res://resources/minigames/minigame_ui/graphic/button_replay_up.png" id="16_eao58"]
|
||||
[ext_resource type="Texture2D" uid="uid://b6b8kb5l3yh04" path="res://resources/minigames/minigame_ui/graphic/large_flower_body.png" id="16_kd3me"]
|
||||
[ext_resource type="Texture2D" uid="uid://dxqnvbr4tffn7" path="res://resources/minigames/minigame_ui/graphic/gauge.png" id="16_m3nil"]
|
||||
[ext_resource type="Texture2D" uid="uid://cfxpnn3uivakv" path="res://resources/minigames/minigame_ui/graphic/gauge_icon_ant_empty.png" id="17_bqwcj"]
|
||||
[ext_resource type="Texture2D" uid="uid://bvu8ud6hkwusb" path="res://resources/minigames/minigame_ui/graphic/button_replay_down.png" id="17_emg5g"]
|
||||
[ext_resource type="Texture2D" uid="uid://d4ffd4us2hrbs" path="res://resources/minigames/minigame_ui/graphic/button_replay_disabled.png" id="18_2y62r"]
|
||||
[ext_resource type="Texture2D" uid="uid://b0ck8jxhicyke" path="res://resources/minigames/minigame_ui/graphic/gauge_icon_ant_full.png" id="18_7tu1d"]
|
||||
[ext_resource type="PackedScene" uid="uid://c4t2cq5vyj4ai" path="res://sources/minigames/base/kalulu.tscn" id="19_wn4nd"]
|
||||
|
||||
[node name="MinigameUI" type="CanvasLayer"]
|
||||
@@ -251,7 +249,6 @@ layout_mode = 2
|
||||
size_flags_horizontal = 8
|
||||
size_flags_vertical = 0
|
||||
mouse_filter = 2
|
||||
texture = ExtResource("17_bqwcj")
|
||||
stretch_mode = 1
|
||||
|
||||
[node name="ProgressionFullIconsRect" type="TextureRect" parent="MainControl/Interface/RightMargin/RightContainer/ProgressionMargin"]
|
||||
@@ -261,7 +258,6 @@ layout_mode = 2
|
||||
size_flags_horizontal = 8
|
||||
size_flags_vertical = 0
|
||||
mouse_filter = 2
|
||||
texture = ExtResource("18_7tu1d")
|
||||
stretch_mode = 1
|
||||
|
||||
[node name="Kalulu" parent="MainControl" instance=ExtResource("19_wn4nd")]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@tool
|
||||
extends CanvasLayer
|
||||
|
||||
signal animation_finished(animation_name: StringName)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@tool
|
||||
extends Minigame
|
||||
|
||||
@export var difficulty: = 1
|
||||
@@ -11,8 +12,7 @@ const difficulty_settings: = {
|
||||
4 : {"crab_rows": [4, 3, 4]},
|
||||
}
|
||||
|
||||
@onready var top_left: = $GameRoot/TopLeft
|
||||
@onready var bottom_right: = $GameRoot/BottomRight
|
||||
@onready var crab_zone: = $GameRoot/CrabZone
|
||||
|
||||
var holes: = []
|
||||
|
||||
@@ -35,12 +35,14 @@ func _setup_minigame() -> void:
|
||||
difficulty = max_difficulty
|
||||
|
||||
var settings: Dictionary = difficulty_settings[difficulty]
|
||||
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)
|
||||
var y: float = (1.0 - fi) * top_left.position.y + fi * bottom_right.position.y
|
||||
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)
|
||||
var x: float = fj * top_left.position.x + (1.0 - fj) * bottom_right.position.x
|
||||
var x: float = fj * top_left.x + (1.0 - fj) * bottom_right.x
|
||||
|
||||
var hole: = hole_class.instantiate()
|
||||
game_root.add_child(hole)
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
script = ExtResource("2_gierf")
|
||||
difficulty = 4
|
||||
minigame_name = "Crabs"
|
||||
max_number_of_lives = 5
|
||||
max_progression = 5
|
||||
help_kalulu_speech = ExtResource("3_vtu3m")
|
||||
win_kalulu_speech = ExtResource("4_eh4op")
|
||||
|
||||
@@ -21,14 +19,28 @@ win_kalulu_speech = ExtResource("4_eh4op")
|
||||
empty_progression_icon = ExtResource("3_s5o38")
|
||||
full_progression_icon = ExtResource("4_a1dm5")
|
||||
|
||||
[node name="Background" type="Sprite2D" parent="GameRoot" index="0"]
|
||||
position = Vector2(1280, 900)
|
||||
scale = Vector2(2, 2)
|
||||
[node name="GameRoot" parent="." index="3"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Background" type="TextureRect" parent="GameRoot" index="0"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("5_0ps1r")
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="TopLeft" type="Node2D" parent="GameRoot" index="1"]
|
||||
position = Vector2(544, 631)
|
||||
|
||||
[node name="BottomRight" type="Node2D" parent="GameRoot" index="2"]
|
||||
position = Vector2(2310, 1675)
|
||||
[node name="CrabZone" type="Control" parent="GameRoot" index="1"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 545.0
|
||||
offset_top = 629.0
|
||||
offset_right = 2311.0
|
||||
offset_bottom = 1673.0
|
||||
|
||||
Reference in New Issue
Block a user