ft: prey collision
This commit is contained in:
@@ -1,37 +1,41 @@
|
||||
extends AbstractPrey
|
||||
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:
|
||||
self.move(Vector3(randfn(0, 1), randfn(0, 1), 0))
|
||||
return
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
self.move(Vector3(randfn(0, 1), randfn(0, 1), 0))
|
||||
|
||||
func move(destination: Vector3) -> void:
|
||||
self.position += Vector2(destination.x, destination.y) # stub
|
||||
move_and_collide(Vector2(destination.x, destination.y))
|
||||
|
||||
func die() -> void:
|
||||
sprite.play("Dying")
|
||||
super.die()
|
||||
|
||||
|
||||
func _on_rigid_body_2d_body_entered(body: Node) -> void:
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
# TODO: collision with other entities
|
||||
# check if colision with player
|
||||
print("we collidin")
|
||||
if body.is_in_group("player"):
|
||||
handle_collision_player(body)
|
||||
else:
|
||||
self.die()
|
||||
|
||||
|
||||
# Function to handle collision logic
|
||||
func handle_collision_player(player):
|
||||
print("Collision!")
|
||||
self.health -= player.str
|
||||
self.health -= player.damage
|
||||
if sprite:
|
||||
if self.health <= 0:
|
||||
self.die()
|
||||
else:
|
||||
sprite.play("injured")
|
||||
sprite.play("Injured")
|
||||
|
||||
Reference in New Issue
Block a user