fx: attacking sprite/logic mismatch

This commit is contained in:
Djairo Hougee 2026-01-17 14:56:25 +01:00
parent c0f5dd4628
commit 0b9b1e75d4
4 changed files with 17 additions and 12 deletions

View File

@ -1,6 +1,6 @@
extends CharacterBody2D
@export var attack_duration = 0.12 # TODO: finetune
@export var attack_duration = 0.2 # TODO: finetune
@export var attack_cooldown_duration = 0.4
@onready var attack_area: Area2D = $AttackArea
@ -20,6 +20,8 @@ func _ready() -> void:
attack_timer.wait_time = attack_duration
attack_cooldown_timer.wait_time = attack_cooldown_duration
func _process(delta):
velocity = Vector2.ZERO
if Input.is_action_pressed("move_right"):
@ -53,16 +55,21 @@ func attack() -> void:
func _on_attack_timeout() -> void:
attack_area.monitoring = false
sprite.play("default")
attack_cooldown_timer.start()
func _on_cooldown_timeout() -> void:
can_attack = true
sprite.play("default")
func _on_attack_hit(body: Node2D) -> void:
var hit_hittable = false
if body.is_in_group("prey") or body.is_in_group("predators"):
if body.has_method("handle_damage"):
body.handle_damage(damage)
hit_hittable = true
elif body.is_in_group("resources"):
pass
if hit_hittable:
await get_tree().create_timer(0.2).timeout
sprite.play("default")
# TODO: resource handling logic

View File

@ -23,8 +23,8 @@ animations = [{
"speed": 5.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_en8op"]
size = Vector2(765.4969, 706.5864)
[sub_resource type="CircleShape2D" id="CircleShape2D_5hxmy"]
radius = 378.18
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_4flbx"]
radius = 191.95984
@ -45,8 +45,8 @@ rotation = -1.5732701
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="AttackArea"]
position = Vector2(29.579561, 730.73236)
shape = SubResource("RectangleShape2D_en8op")
position = Vector2(41.029465, 288.86832)
shape = SubResource("CircleShape2D_5hxmy")
debug_color = Color(0.80813414, 0.3957308, 0.3356335, 0.41960785)
[node name="CollisionShape2D" type="CollisionShape2D" parent="." groups=["player"]]

View File

@ -50,11 +50,10 @@ func die() -> void:
super.die()
func become_injured() -> void:
sprite.animation = "Injured"
mirrorSprite1.animation = "Injured"
mirrorSprite2.animation = "Injured"
mirrorSprite3.animation = "Injured"
sprite.play()
sprite.play("Injured")
mirrorSprite1.play("Injured")
mirrorSprite2.play("Injured")
mirrorSprite3.play("Injured")
# Mirroring table:
# |---|---|---|---|

View File

@ -55,4 +55,3 @@ maxHealth = 20
scale = Vector2(0.1, 0.1)
sprite_frames = SubResource("SpriteFrames_66x8p")
animation = &"Dying"
frame_progress = 0.60472965