Fixes crabs minigame FXs. Adds highlight to the crabs
This commit is contained in:
@@ -8,6 +8,7 @@ signal crab_hit(stimulus: Dictionary)
|
||||
@onready var animated_sprite: = %AnimatedSprite2D
|
||||
@onready var label: = %AutoSizeLabel.get_node("Label")
|
||||
@onready var button: = $Button
|
||||
@onready var highlight_fx: = %HighlightFX
|
||||
@onready var right_fx: = %RightFX
|
||||
@onready var wrong_fx: = %WrongFX
|
||||
|
||||
@@ -30,6 +31,14 @@ func is_button_pressed() -> bool:
|
||||
return true
|
||||
|
||||
|
||||
func highlight() -> void:
|
||||
highlight_fx.play()
|
||||
|
||||
|
||||
func is_highlighted() -> bool:
|
||||
return highlight_fx.is_playing
|
||||
|
||||
|
||||
func right() -> void:
|
||||
right_fx.play()
|
||||
await right_fx.finished
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
[gd_scene load_steps=36 format=3 uid="uid://bwe3fp0vkpufb"]
|
||||
[gd_scene load_steps=37 format=3 uid="uid://bwe3fp0vkpufb"]
|
||||
|
||||
[ext_resource type="Script" path="res://sources/minigames/crabs/crab/crab.gd" id="1_5hgg8"]
|
||||
[ext_resource type="Texture2D" uid="uid://c36217nu30yh3" path="res://assets/minigames/crabs/graphic/crab_spritesheet.png" id="2_yu4q0"]
|
||||
[ext_resource type="Script" path="res://sources/utils/sprite_control.gd" id="3_e1twq"]
|
||||
[ext_resource type="PackedScene" uid="uid://cge0uyn30tcpv" path="res://sources/utils/fx/highlight.tscn" id="3_is4em"]
|
||||
[ext_resource type="PackedScene" uid="uid://cn2rw06pltyiu" path="res://sources/utils/fx/right.tscn" id="4_3hx0j"]
|
||||
[ext_resource type="PackedScene" uid="uid://dlmbxcgiv8tpr" path="res://sources/utils/fx/wrong.tscn" id="5_3sw4w"]
|
||||
[ext_resource type="Script" path="res://sources/utils/percent_margin_container.gd" id="6_bn4pr"]
|
||||
@@ -225,6 +226,18 @@ scale = Vector2(0.5, 0.5)
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="HighlightFX" parent="BackFX" instance=ExtResource("3_is4em")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
scale = Vector2(0.5, 0.5)
|
||||
|
||||
[node name="Body" type="Control" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
@@ -249,7 +262,7 @@ unique_name_in_owner = true
|
||||
sprite_frames = SubResource("SpriteFrames_g5q5i")
|
||||
animation = &"idle1"
|
||||
autoplay = "idle1"
|
||||
frame_progress = 0.0800428
|
||||
frame_progress = 0.441566
|
||||
centered = false
|
||||
offset = Vector2(-5, 0)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ var difficulty_settings: Array[DifficultySettings] = [
|
||||
@onready var crab_zone: = $GameRoot/CrabZone
|
||||
|
||||
var holes: Array[Hole] = []
|
||||
|
||||
var is_highlighting : bool = false
|
||||
|
||||
# ------------ Initialisation ------------
|
||||
|
||||
@@ -48,6 +48,7 @@ func _setup_minigame() -> void:
|
||||
hole.position = Vector2(x, y)
|
||||
|
||||
if not Engine.is_editor_hint():
|
||||
hole.crab_out.connect(_on_hole_crab_out.bind(hole))
|
||||
hole.stimulus_hit.connect(_on_stimulus_pressed.bind(hole))
|
||||
hole.crab_despawned.connect(_on_hole_crab_despawned)
|
||||
stimulus_heard.connect(hole.on_stimulus_heard)
|
||||
@@ -65,6 +66,13 @@ func _get_difficulty_settings() -> DifficultySettings:
|
||||
return difficulty_settings[difficulty]
|
||||
|
||||
|
||||
func _highlight():
|
||||
is_highlighting = true
|
||||
for hole in holes:
|
||||
if hole.crab and hole.crab_visible and _is_stimulus_right(hole.crab.stimulus):
|
||||
hole.highlight()
|
||||
|
||||
|
||||
func _on_stimulus_pressed(stimulus: Dictionary, hole: Hole) -> bool:
|
||||
if not super(stimulus, hole):
|
||||
return false
|
||||
@@ -73,6 +81,7 @@ func _on_stimulus_pressed(stimulus: Dictionary, hole: Hole) -> bool:
|
||||
if is_right:
|
||||
hole.right()
|
||||
current_progression += 1
|
||||
is_highlighting = false
|
||||
else:
|
||||
hole.wrong()
|
||||
current_lives -= 1
|
||||
@@ -100,6 +109,11 @@ func _spawn_crabs() -> void:
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
|
||||
|
||||
func _on_hole_crab_out(hole : Hole) -> void:
|
||||
if is_highlighting and _is_stimulus_right(hole.crab.stimulus):
|
||||
hole.highlight()
|
||||
|
||||
|
||||
func _on_hole_crab_despawned() -> void:
|
||||
if await _await_for_future_or_stimulus_found(get_tree().create_timer(randf_range(0.1, 2.0)).timeout):
|
||||
return
|
||||
|
||||
@@ -4,45 +4,78 @@ class_name Hole
|
||||
signal stimulus_hit(stimulus: Dictionary)
|
||||
signal crab_despawned()
|
||||
signal stop()
|
||||
signal crab_out(hole : Hole)
|
||||
|
||||
const crab_scene: = preload("res://sources/minigames/crabs/crab/crab.tscn")
|
||||
const crab_spawn_y: float = 100.
|
||||
const crab_middle_y: float = 20.
|
||||
const crab_out_y: float = -130.
|
||||
const crab_up_y: float = -180.
|
||||
|
||||
@onready var hole_back: = $HoleBack
|
||||
@onready var hole_front: = $HoleFront
|
||||
@onready var mask: = $Mask
|
||||
@onready var sand_vfx: SandVFX = $SandVFX
|
||||
@onready var timer: = $Timer
|
||||
@onready var crab_audio_stream_player: = $CrabAudioStreamPlayer2D
|
||||
@onready var crab_audio_stream_player: CrabAudioStreamPlayer = $CrabAudioStreamPlayer2D
|
||||
|
||||
var crab: Crab
|
||||
|
||||
var crab_x : float
|
||||
var stimulus_heard: bool = false:
|
||||
set(value):
|
||||
stimulus_heard = value
|
||||
_set_crab_button_active(stimulus_heard and crab_visible)
|
||||
|
||||
var crab_visible: bool = false:
|
||||
set(value):
|
||||
crab_visible = value
|
||||
_set_crab_button_active(stimulus_heard and crab_visible)
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
if not crab:
|
||||
if sand_vfx.is_playing:
|
||||
sand_vfx.stop()
|
||||
|
||||
if crab_audio_stream_player.is_playing:
|
||||
crab_audio_stream_player.stop_playing()
|
||||
|
||||
return
|
||||
|
||||
# Handles the sounds and VFX when the crab is not out yet
|
||||
if crab.position.y >= crab_middle_y:
|
||||
if crab_visible:
|
||||
crab_visible = false
|
||||
|
||||
if not sand_vfx.is_playing:
|
||||
sand_vfx.start()
|
||||
|
||||
if not crab_audio_stream_player.is_playing:
|
||||
crab_audio_stream_player.start_playing()
|
||||
# Handles the sounds and VFX when the crab is out
|
||||
else:
|
||||
if not crab_visible:
|
||||
crab_visible = true
|
||||
|
||||
if sand_vfx.is_playing:
|
||||
sand_vfx.stop()
|
||||
|
||||
if crab_audio_stream_player.is_playing:
|
||||
crab_audio_stream_player.stop_playing()
|
||||
|
||||
|
||||
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_x = -crab.size.x / 2
|
||||
crab.position = Vector2(crab_x, crab_spawn_y)
|
||||
crab.stimulus = stimulus
|
||||
|
||||
# Show the crab but not the stimulus
|
||||
sand_vfx.start()
|
||||
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))
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, crab_middle_y), randf_range(0.25, 2.0))
|
||||
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))
|
||||
@@ -50,64 +83,30 @@ func spawn_crab(stimulus: Dictionary) -> void:
|
||||
return
|
||||
|
||||
# The crab gets completely out
|
||||
sand_vfx.stop()
|
||||
crab_audio_stream_player.start_playing()
|
||||
crab_out.emit()
|
||||
tween = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, -130.0), 0.5)
|
||||
crab_visible = true
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, crab_out_y), 0.5)
|
||||
if await is_button_pressed_with_limit(tween.finished):
|
||||
return
|
||||
crab_audio_stream_player.stop_playing()
|
||||
|
||||
timer.start(randf_range(1.0, 2.5))
|
||||
if await is_button_pressed_with_limit(timer.timeout):
|
||||
return
|
||||
|
||||
# The crab disappears in the hole
|
||||
crab_audio_stream_player.start_playing()
|
||||
tween = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, 100.0), 0.5)
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, crab_spawn_y), 0.5)
|
||||
if await is_button_pressed_with_limit(tween.finished):
|
||||
return
|
||||
sand_vfx.play()
|
||||
crab_audio_stream_player.stop_playing()
|
||||
|
||||
# Destroy the crab
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
|
||||
# Emit the despawned signal
|
||||
crab_despawned.emit()
|
||||
|
||||
|
||||
func despawn_crab() -> void:
|
||||
if not crab:
|
||||
return
|
||||
|
||||
var crab_x : float = -crab.size.x / 2
|
||||
|
||||
crab_visible = false
|
||||
crab_audio_stream_player.stop_playing()
|
||||
|
||||
# Move the crab up and rotate
|
||||
var tween: = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, -180), 0.5)
|
||||
tween.parallel().tween_property(crab.body, "rotation_degrees", 540.0, 0.5)
|
||||
await tween.finished
|
||||
|
||||
# Make the crab disappear in the hole
|
||||
tween = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, 100.0), 0.5)
|
||||
await tween.finished
|
||||
sand_vfx.play()
|
||||
|
||||
# No idea what this does
|
||||
if not timer.is_stopped():
|
||||
timer.start(0.4)
|
||||
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
|
||||
#crab_despawned.emit()
|
||||
|
||||
|
||||
func is_button_pressed_with_limit(future : Signal) -> bool:
|
||||
var coroutine: = Coroutine.new()
|
||||
coroutine.add_future(crab.is_button_pressed)
|
||||
@@ -124,35 +123,55 @@ func is_button_pressed_with_limit(future : Signal) -> bool:
|
||||
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)
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, crab_spawn_y), 0.5)
|
||||
await tween.finished
|
||||
sand_vfx.play()
|
||||
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func highlight() -> void:
|
||||
crab.highlight()
|
||||
|
||||
|
||||
func right() -> void:
|
||||
crab.right()
|
||||
|
||||
|
||||
func wrong() -> void:
|
||||
crab.wrong()
|
||||
|
||||
|
||||
func _set_crab_button_active(is_active : bool):
|
||||
if crab:
|
||||
crab.set_button_active(is_active)
|
||||
|
||||
|
||||
func right() -> void:
|
||||
crab.right()
|
||||
despawn_crab()
|
||||
|
||||
|
||||
func wrong() -> void:
|
||||
crab.wrong()
|
||||
despawn_crab()
|
||||
# ------------ Connections ------------
|
||||
|
||||
|
||||
func _on_crab_hit(stimulus: Dictionary) -> void:
|
||||
|
||||
# Emit the stimulus
|
||||
stimulus_hit.emit(stimulus)
|
||||
|
||||
# Move the crab up and rotate
|
||||
var tween: = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, crab_up_y), 0.5)
|
||||
tween.parallel().tween_property(crab.body, "rotation_degrees", 540.0, 0.5)
|
||||
await tween.finished
|
||||
|
||||
# Make the crab disappear in the hole
|
||||
tween = create_tween()
|
||||
tween.tween_property(crab, "position", Vector2(crab_x, crab_spawn_y), 0.5)
|
||||
await tween.finished
|
||||
|
||||
crab.queue_free()
|
||||
crab = null
|
||||
|
||||
|
||||
func on_stimulus_heard(is_heard : bool):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends AudioStreamPlayer2D
|
||||
class_name CrabAudioStreamPlayer
|
||||
|
||||
const crab_sound_list: = [
|
||||
preload("res://assets/minigames/crabs/audio/sfx/crab_random_1.mp3"),
|
||||
@@ -16,19 +17,19 @@ const crab_sound_list: = [
|
||||
preload("res://assets/minigames/crabs/audio/sfx/crab_random_1.mp3"),
|
||||
]
|
||||
|
||||
var should_play: = false
|
||||
var is_playing: = false
|
||||
|
||||
|
||||
func start_playing() -> void:
|
||||
should_play = true
|
||||
is_playing = true
|
||||
_on_finished()
|
||||
|
||||
|
||||
func stop_playing() -> void:
|
||||
should_play = false
|
||||
is_playing = false
|
||||
|
||||
|
||||
func _on_finished() -> void:
|
||||
if should_play:
|
||||
if is_playing:
|
||||
stream = crab_sound_list[randi() % crab_sound_list.size()]
|
||||
playing = true
|
||||
|
||||
@@ -15,7 +15,7 @@ layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 400.0
|
||||
offset_bottom = 400.0
|
||||
scale = Vector2(1.07673, 1.07673)
|
||||
scale = Vector2(1.02031, 1.02031)
|
||||
script = ExtResource("1_06uwq")
|
||||
|
||||
[node name="BackFX" type="Control" parent="."]
|
||||
@@ -68,7 +68,6 @@ unique_name_in_owner = true
|
||||
scale = Vector2(2.15054, 2.15054)
|
||||
sprite_frames = ExtResource("5_bh1cr")
|
||||
animation = &"idle"
|
||||
frame_progress = 0.365226
|
||||
centered = false
|
||||
offset = Vector2(-0.000205994, 0.00019455)
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
extends Control
|
||||
class_name HighlightFX
|
||||
|
||||
@onready var animation_player: = $AnimationPlayer
|
||||
|
||||
var is_playing : bool = false
|
||||
|
||||
func play() -> void:
|
||||
is_playing = true
|
||||
animation_player.play("highlight")
|
||||
|
||||
|
||||
func stop() -> void:
|
||||
is_playing = false
|
||||
animation_player.play("stop")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends Control
|
||||
class_name RightFX
|
||||
|
||||
signal finished()
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ const textures: Array[Resource] = [
|
||||
@onready var particles : GPUParticles2D = $Particles
|
||||
@onready var timer : Timer = $Timer
|
||||
|
||||
var is_playing : bool = false
|
||||
|
||||
func _ready():
|
||||
timer.wait_time = particles.lifetime
|
||||
@@ -27,10 +28,12 @@ func play():
|
||||
|
||||
|
||||
func start():
|
||||
is_playing = true
|
||||
_on_timer_timeout()
|
||||
|
||||
|
||||
func stop():
|
||||
is_playing = false
|
||||
timer.stop()
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends Control
|
||||
class_name WrongFX
|
||||
|
||||
signal finished()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user