mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-21 23:34:18 +00:00
Add collector entity
This commit is contained in:
parent
2d864c8c28
commit
e90830cd06
4 changed files with 57 additions and 0 deletions
23
collector/collectible.gd
Normal file
23
collector/collectible.gd
Normal 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()
|
6
collector/collectible.tscn
Normal file
6
collector/collectible.tscn
Normal 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
20
collector/collector.gd
Normal 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
8
collector/collector.tscn
Normal 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"]
|
Loading…
Reference in a new issue