1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 08:04:23 +00:00
hella-farm/entities/sacrifice_stone.gd

31 lines
949 B
GDScript3
Raw Permalink Normal View History

2024-04-27 18:12:03 +00:00
extends Node2D
class_name SacrificeStone
## The sacrificial stone where entities can be placed on.
##
## Entities use [MovementHunter] to move towards the center of the stone.
2024-04-28 09:33:18 +00:00
## Emitted when the sacrifice on top of the stone changes.
signal sacrifice_changed(entity: PhysicsBody2D)
2024-04-27 18:12:03 +00:00
## The entity currently on top of the stone.
var entity: PhysicsBody2D
2024-04-27 18:12:03 +00:00
func _on_tracked(body: PhysicsBody2D):
# If a entity is dragged on top of the SacrificeStone while another entity is already on top of it, ignore the capture and let the collision resolve instead
if entity != null:
2024-04-27 18:12:03 +00:00
return
# Make sure the entity is sacrificable, and if it is, lock it in and emit [signal sacrifice_changed].
2024-04-28 09:23:07 +00:00
var types: Array = body.find_children("*", "Sacrificable", false, false)
2024-04-27 18:12:03 +00:00
for type in types:
entity = body
sacrifice_changed.emit(body)
2024-04-27 18:12:03 +00:00
break
func _on_untracked(body: PhysicsBody2D):
if body == entity:
entity = null
sacrifice_changed.emit(null)