notSpore/evolve-die-repeat/molecular/nucleotide_prey.gd

45 lines
1.1 KiB
GDScript

extends AbstractPrey2D
@onready var sprite = get_node("AnimatedSprite2D")
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
$AnimatedSprite2D.animation = "Healthy"
$AnimatedSprite2D.play()
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
return
func _physics_process(delta: float) -> void:
self.move(Vector3(randfn(0, 1), randfn(0, 1), 0))
func move(motion: Vector3) -> void:
move_and_collide(Vector2(motion.x, motion.y)) # Moves along the given vector
# Apply boundary to new position
position = GameManager.get_boundaried_position(position)
func die() -> void:
sprite.play("Dying")
super.die()
func _on_area_2d_body_entered(body: Node2D) -> void:
# TODO: collision with other entities
# check if colision with player
if body.is_in_group("player"):
handle_collision_player(body)
# Function to handle collision logic
func handle_collision_player(player):
self.health -= player.damage
if sprite:
if self.health <= 0:
self.die()
else:
sprite.play("Injured")