33 lines
965 B
GDScript
33 lines
965 B
GDScript
extends AbstractFood
|
|
class_name FoodMolecular
|
|
|
|
@onready var collision: Area2D = $Collision
|
|
@onready var sprite: AnimatedSprite2D = $Collision/Sprite
|
|
|
|
func _ready() -> void:
|
|
sprite.play()
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var dpos = Vector2(GameManager.flow_x, GameManager.flow_y) * delta * flow_carry_speed
|
|
collision.position = GameManager.get_boundaried_position(collision.position + dpos)
|
|
|
|
func _process(delta):
|
|
collision.position = GameManager.get_boundaried_position(collision.position)
|
|
|
|
func _on_body_entered(body: Node2D) -> void:
|
|
eat(body)
|
|
|
|
func eat(consumer: Node2D) -> void:
|
|
print(consumer.name + " ate: ", food_name)
|
|
consumed.emit()
|
|
|
|
apply_effect(consumer)
|
|
|
|
queue_free()
|
|
|
|
func apply_effect(consumer: Node2D) -> void:
|
|
if consumer.has_method("collect_resource"): # TODO: Define a "consumer" group instead?
|
|
consumer.collect_resource(val) # val is from parent (default 1), override if required
|
|
# TODO: *Some cool effect here*
|