mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-25 00:54:19 +00:00
Document collector entity
This commit is contained in:
parent
e90830cd06
commit
a3826b9801
3 changed files with 33 additions and 16 deletions
|
@ -1,23 +1,18 @@
|
|||
extends Node
|
||||
class_name Collectible
|
||||
## A marker for collectible entities.
|
||||
##
|
||||
## Used by [Collector]s to determine which entities to pick up.
|
||||
|
||||
enum CollectibleType {
|
||||
UNSET,
|
||||
COIN_COPPER,
|
||||
COIN_SILVER,
|
||||
COIN_GOLD,
|
||||
GEM,
|
||||
DIAMOND,
|
||||
COAL,
|
||||
CROWN,
|
||||
SUPERCROWN,
|
||||
}
|
||||
|
||||
@export var type: CollectibleType
|
||||
## The type of collectible entity the parent entity represents.
|
||||
@export var type: StringName
|
||||
|
||||
## Emitted when this entity has been collected by a collector.
|
||||
signal collected
|
||||
|
||||
|
||||
## Mark this entity as collected.
|
||||
##
|
||||
## You'll probably want to connect this to an AudioSource2D, which will disable the node and play a sound, and when the sound is over a new signal will queue_free it.
|
||||
func collect():
|
||||
emit_signal("collected")
|
||||
get_parent().queue_free()
|
||||
|
|
|
@ -1,14 +1,30 @@
|
|||
extends Area2D
|
||||
class_name Collector
|
||||
## Area that will pick up [Collectible]s with a given name, keeping track of the amount collected.
|
||||
|
||||
|
||||
## The current amount of collected entities.
|
||||
var collected_count: int = 0
|
||||
|
||||
@export var collecting_types: Array[Collectible.CollectibleType]
|
||||
## The types of [Collectible]s to pick up.
|
||||
##
|
||||
## The strings will match only if exactly the same.
|
||||
@export var collecting_types: Array[StringName]
|
||||
|
||||
## The collision mask to check colliding body against.
|
||||
@export_flags_2d_physics var collecting_collision_mask: int
|
||||
|
||||
## The goal amount of entities to collect.
|
||||
##
|
||||
## When [collected_count] reaches it, it will be reset to zero, and the "goal" signal will be emitted.
|
||||
@export var collecting_amount: int
|
||||
|
||||
## The collector has picked up an object.
|
||||
signal collected(what: PhysicsBody2D)
|
||||
|
||||
## The collector has received its collection goal and is about to reset.
|
||||
signal goal
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D):
|
||||
if body is PhysicsBody2D:
|
||||
|
@ -18,3 +34,6 @@ func _on_body_entered(body: Node2D):
|
|||
collected_count += 1
|
||||
collectible.collect()
|
||||
emit_signal("collected", body)
|
||||
if collected_count >= collecting_amount:
|
||||
emit_signal("goal")
|
||||
collected_count = 0
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://c3kitncwpi42j"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://c3kitncwpi42j"]
|
||||
|
||||
[ext_resource type="PhysicsMaterial" uid="uid://c6kn1an85lccr" path="res://entity/coin_physics_material.tres" id="1_8k46m"]
|
||||
[ext_resource type="Texture2D" uid="uid://dbdkb4vt7dh85" path="res://entity/coin_copper_4.png" id="1_wedw1"]
|
||||
[ext_resource type="Texture2D" uid="uid://2vtvoj6ua3cb" path="res://entity/coin_copper_outline_2.png" id="2_2ifq3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bk1vvq5rug01m" path="res://collector/collectible.tscn" id="4_yefrx"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_c6byl"]
|
||||
size = Vector2(16, 5)
|
||||
|
@ -28,3 +29,5 @@ texture = ExtResource("1_wedw1")
|
|||
z_index = -10
|
||||
texture_filter = 1
|
||||
texture = ExtResource("2_2ifq3")
|
||||
|
||||
[node name="Collectible" parent="." instance=ExtResource("4_yefrx")]
|
||||
|
|
Loading…
Reference in a new issue