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 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 @export var attack_cooldown_duration = 0.4
@onready var attack_area: Area2D = $AttackArea @onready var attack_area: Area2D = $AttackArea
@ -19,6 +19,8 @@ func _ready() -> void:
attack_area.monitoring = false # no collision until attacking attack_area.monitoring = false # no collision until attacking
attack_timer.wait_time = attack_duration attack_timer.wait_time = attack_duration
attack_cooldown_timer.wait_time = attack_cooldown_duration attack_cooldown_timer.wait_time = attack_cooldown_duration
func _process(delta): func _process(delta):
velocity = Vector2.ZERO velocity = Vector2.ZERO
@ -53,16 +55,21 @@ func attack() -> void:
func _on_attack_timeout() -> void: func _on_attack_timeout() -> void:
attack_area.monitoring = false attack_area.monitoring = false
sprite.play("default")
attack_cooldown_timer.start() attack_cooldown_timer.start()
func _on_cooldown_timeout() -> void: func _on_cooldown_timeout() -> void:
can_attack = true can_attack = true
sprite.play("default")
func _on_attack_hit(body: Node2D) -> void: 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.is_in_group("prey") or body.is_in_group("predators"):
if body.has_method("handle_damage"): if body.has_method("handle_damage"):
body.handle_damage(damage) body.handle_damage(damage)
hit_hittable = true
elif body.is_in_group("resources"): elif body.is_in_group("resources"):
pass pass
if hit_hittable:
await get_tree().create_timer(0.2).timeout
sprite.play("default")
# TODO: resource handling logic # TODO: resource handling logic

View File

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

View File

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

View File

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