1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 23:54:23 +00:00

Create Eater behaviour

This commit is contained in:
Steffo 2024-04-15 01:23:06 +02:00
parent 484c61caa3
commit 5dd3c62410
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
3 changed files with 43 additions and 1 deletions

21
behaviours/eater.gd Normal file
View file

@ -0,0 +1,21 @@
extends Area2D
class_name Eater
signal eaten(edible: Edible)
@export var tag: StringName
func _on_body_entered(body: Node2D) -> void:
var edibles: Array = body.find_children("Edible", "Edible", false, false)
for edible in edibles:
if edible.tag == tag:
eaten.emit(edible)
edible.eat()
func _on_eaten(edible: Edible) -> void:
Log.p(self, "Eaten: %s" % edible)

16
behaviours/eater.tscn Normal file
View file

@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=3 uid="uid://jg7qkbswgqjc"]
[ext_resource type="Script" path="res://behaviours/eater.gd" id="1_urx5y"]
[sub_resource type="CircleShape2D" id="CircleShape2D_61hv0"]
radius = 16.0
[node name="Eater" type="Area2D"]
script = ExtResource("1_urx5y")
[node name="Shape" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_61hv0")
debug_color = Color(0.47451, 0, 0.027451, 0.678431)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]

View file

@ -2,7 +2,12 @@ extends Node
class_name Edible
signal eaten(tag: StringName)
signal eaten
func eat():
eaten.emit()
get_parent().queue_free()
@export var tag: StringName