Skip to content

Commit 09abd29

Browse files
authored
Merge pull request #1325 from endlessm/filling-docs
Document the components of the fill-matching game mechanic
2 parents fe4b31f + 5b4b879 commit 09abd29

File tree

7 files changed

+67
-14
lines changed

7 files changed

+67
-14
lines changed

scenes/game_elements/characters/enemies/throwing_enemy/components/throwing_enemy.gd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# SPDX-FileCopyrightText: The Threadbare Authors
22
# SPDX-License-Identifier: MPL-2.0
33
@tool
4-
## Enemy that throws projectiles to the player.
54
class_name ThrowingEnemy
65
extends CharacterBody2D
6+
## Enemy that throws [Projectile]s to the player.
7+
##
8+
## @tutorial: https://github.com/endlessm/threadbare/discussions/1323
9+
##
10+
## This is a piece of the fill-matching mechanic.
11+
## [br][br]
12+
## When throwing, the label/color of the projectile is picked from
13+
## [member allowed_labels] and [member color_per_label].
714

815
enum State { IDLE, WALKING, ATTACKING, DEFEATED }
916

scenes/game_elements/props/filling_barrel/components/filling_barrel.gd

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
@tool
44
class_name FillingBarrel
55
extends StaticBody2D
6-
6+
## A barrel that starts empty and gets filled until completion
7+
##
8+
## @tutorial: https://github.com/endlessm/threadbare/discussions/1323
9+
##
10+
## This is a piece of the fill-matching mechanic.
11+
## [br][br]
12+
## Call [member fill()] to increment the amount. When
13+
## [member needed_amount] is reached, the [signal completed]
14+
## is emited.
15+
16+
## Emited when the barrel amount reaches [member needed_amount].
717
signal completed
818

919
const DEFAULT_SPRITE_FRAMES: SpriteFrames = preload("uid://dlsq0ke41s1yh")
@@ -61,13 +71,13 @@ func _ready() -> void:
6171
animated_sprite_2d.frame = 0
6272

6373

64-
## Increment the amount by one and play the fill animation. If completed, also play the completed
74+
## Increment the amount and play an animation. If completed, also play the completed
6575
## animation and remove this barrel from the current scene.
66-
func fill() -> void:
76+
func increment(by: int = 1) -> void:
6777
if _amount >= needed_amount:
6878
return
69-
animation_player.play(&"fill")
70-
_amount += 1
79+
animation_player.play(&"increment")
80+
_amount += by
7181
animated_sprite_2d.frame = floor(float(_amount) / needed_amount * _total_frames())
7282
if _amount >= needed_amount:
7383
_disable_collisions.call_deferred()

scenes/game_elements/props/filling_barrel/filling_barrel.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ tracks/3/keys = {
106106
}
107107

108108
[sub_resource type="Animation" id="Animation_fs5vc"]
109-
resource_name = "fill"
109+
resource_name = "increment"
110110
length = 0.8
111111
tracks/0/type = "audio"
112112
tracks/0/imported = false
@@ -152,7 +152,7 @@ tracks/2/keys = {
152152
_data = {
153153
&"RESET": SubResource("Animation_tu5xq"),
154154
&"completed": SubResource("Animation_6inx0"),
155-
&"fill": SubResource("Animation_fs5vc")
155+
&"increment": SubResource("Animation_fs5vc")
156156
}
157157

158158
[node name="FillingBarrel" type="StaticBody2D" groups=["filling_barrels"]]

scenes/game_elements/props/projectile/components/projectile.gd

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
# SPDX-FileCopyrightText: The Threadbare Authors
22
# SPDX-License-Identifier: MPL-2.0
3-
## A RigidBody2D that can be thrown between enemies and player. It has a label too, and it can
4-
## be used to fill barrels with the matching label.
53
class_name Projectile
64
extends RigidBody2D
5+
## A projectile that can fill matching [FillingBarrel]s.
6+
##
7+
## @tutorial: https://github.com/endlessm/threadbare/discussions/1323
8+
##
9+
## This is a piece of the fill-matching mechanic.
10+
## [br][br]
11+
## The projectile has a [member label] and optionally a [member color]
12+
## to tint it.
13+
## When the projectile collides with a [FillingBarrel] and both labels match,
14+
## it calls [member FillingBarrel.increment()] and is removed.
15+
## [br][br]
16+
## The projectile will live in the scene until [member duration_timer] times up.
17+
## When the projectile collides with anything, this timer is resetted, so the
18+
## projectile life is expanded.
719

820
## The projectile can fill barrels with the matching label.
921
@export var label: String = "???"
@@ -61,7 +73,13 @@ var _trail_particles: GPUParticles2D
6173
@onready var visible_things: Node2D = %VisibleThings
6274
@onready var animated_sprite_2d: AnimatedSprite2D = %AnimatedSprite2D
6375
@onready var trail_fx_marker: Marker2D = %TrailFXMarker
76+
77+
## How long the projectile lives in the scene.
78+
## [br][br]
79+
## This timer is restarted each time the projectile collides with anything.
80+
## So the life of the projectile is extended in each collision.
6481
@onready var duration_timer: Timer = %DurationTimer
82+
6583
@onready var hit_sound: AudioStreamPlayer2D = %HitSound
6684

6785

@@ -142,7 +160,7 @@ func _on_body_entered(body: Node2D) -> void:
142160
if body.owner is FillingBarrel:
143161
var filling_barrel: FillingBarrel = body.owner as FillingBarrel
144162
if filling_barrel.label == label:
145-
filling_barrel.fill()
163+
filling_barrel.increment()
146164
queue_free()
147165

148166

scenes/game_logic/fill_game_logic.gd

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,31 @@
22
# SPDX-License-Identifier: MPL-2.0
33
class_name FillGameLogic
44
extends Node
5+
## Manages the logic of the fill-matching game.
6+
##
7+
## @tutorial: https://github.com/endlessm/threadbare/discussions/1323
8+
##
9+
## This is a piece of the fill-matching mechanic.
10+
## [br][br]
11+
## Grabs the label and optional color of each [FillingBarrel] that exist in the
12+
## current scene, and assigns them as the allowed label/color of the [Projectile]
13+
## that each [ThrowingEnemy] is allowed to throw.
14+
## Each time a [FillingBarrel] is filled, perform the label/color assignment again
15+
## so [ThrowingEnemy]s only throw projectiles that can increase the amount of
16+
## the remaining barrels.
17+
## [br][br]
18+
## Also keep track of the completed [FillingBarrel]s and emit [signal goal_reached]
19+
## when [member barrels_to_win] is reached.
520

21+
## Emited when [member barrels_completed] reaches [member barrels_to_win].
622
signal goal_reached
723

24+
## How many barrels to complete for winning.
825
@export var barrels_to_win: int = 1
26+
927
@export var intro_dialogue: DialogueResource
1028

29+
## Counter for the completed barrels.
1130
var barrels_completed: int = 0
1231

1332

scenes/quests/story_quests/el_juguete_perdido/2_combat/combat.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ animations = [{
8383

8484
[sub_resource type="Resource" id="Resource_a51xm"]
8585
script = ExtResource("9_w3dy0")
86-
name = ""
8786
type = 1
8887
metadata/_custom_type_script = "uid://bgmwplmj3bfls"
8988

scenes/quests/story_quests/el_juguete_perdido/objects_components/barrel.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ tracks/3/keys = {
106106
}
107107

108108
[sub_resource type="Animation" id="Animation_fs5vc"]
109-
resource_name = "fill"
109+
resource_name = "increment"
110110
length = 0.8
111111
tracks/0/type = "audio"
112112
tracks/0/imported = false
@@ -152,7 +152,7 @@ tracks/2/keys = {
152152
_data = {
153153
&"RESET": SubResource("Animation_tu5xq"),
154154
&"completed": SubResource("Animation_6inx0"),
155-
&"fill": SubResource("Animation_fs5vc")
155+
&"increment": SubResource("Animation_fs5vc")
156156
}
157157

158158
[node name="FillingBarrel" type="StaticBody2D" groups=["filling_barrels"]]

0 commit comments

Comments
 (0)