1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-22 07:44:17 +00:00

Add collector entity

This commit is contained in:
Steffo 2023-10-01 03:03:03 +02:00
parent 2d864c8c28
commit e90830cd06
Signed by: steffo
GPG key ID: 2A24051445686895
4 changed files with 57 additions and 0 deletions

23
collector/collectible.gd Normal file
View file

@ -0,0 +1,23 @@
extends Node
class_name Collectible
enum CollectibleType {
UNSET,
COIN_COPPER,
COIN_SILVER,
COIN_GOLD,
GEM,
DIAMOND,
COAL,
CROWN,
SUPERCROWN,
}
@export var type: CollectibleType
signal collected
func collect():
emit_signal("collected")
get_parent().queue_free()

View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bk1vvq5rug01m"]
[ext_resource type="Script" path="res://collector/collectible.gd" id="1_qilbk"]
[node name="Collectible" type="Node"]
script = ExtResource("1_qilbk")

20
collector/collector.gd Normal file
View file

@ -0,0 +1,20 @@
extends Area2D
class_name Collector
var collected_count: int = 0
@export var collecting_types: Array[Collectible.CollectibleType]
@export_flags_2d_physics var collecting_collision_mask: int
signal collected(what: PhysicsBody2D)
func _on_body_entered(body: Node2D):
if body is PhysicsBody2D:
if body.collision_layer & collecting_collision_mask:
var collectible: Collectible = body.get_node("Collectible")
if collectible.type in collecting_types:
collected_count += 1
collectible.collect()
emit_signal("collected", body)

8
collector/collector.tscn Normal file
View file

@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://c5w3b55aiui6c"]
[ext_resource type="Script" path="res://collector/collector.gd" id="1_1xtt5"]
[node name="Collector" type="Area2D"]
script = ExtResource("1_1xtt5")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]