ft: player attacking logic

This commit is contained in:
2026-01-17 14:20:54 +01:00
parent 5811658c64
commit 18ce1716e4
8 changed files with 92 additions and 61 deletions

View File

@@ -10,8 +10,9 @@ var mirrorSprite3: Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
$AnimatedSprite2D.animation = "Healthy"
$AnimatedSprite2D.play()
health = maxHealth
sprite.animation = "Healthy"
sprite.play()
mirrorSprite1 = sprite.duplicate()
mirrorSprite2 = sprite.duplicate()
@@ -28,7 +29,8 @@ func _process(delta: float) -> void:
_handle_wrapping()
func _physics_process(delta: float) -> void:
self.move(Vector3(randfn(0, 1), randfn(0, 1), 0))
#self.move(Vector3(randfn(0, 1), randfn(0, 1), 0))
pass
func move(motion: Vector3) -> void:
move_and_collide(Vector2(motion.x, motion.y)) # Moves along the given vector
@@ -36,26 +38,20 @@ func move(motion: Vector3) -> void:
# Apply boundary to new position
position = GameManager.get_boundaried_position(position)
func handle_damage(dmg: int) -> void:
health = max(0, health-dmg)
if health == 0:
die()
if health < maxHealth:
become_injured()
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")
func become_injured() -> void:
sprite.animation = "Injured"
sprite.play()
# FIXME: Doesn't work with injured sprite
# Mirroring table: