From 93497002ffb46499874bfd662ae64fff567ccd60 Mon Sep 17 00:00:00 2001 From: Diego De la Viuda Llorente Date: Fri, 16 Oct 2026 13:13:57 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9E=95ADD:=20Stun=20al=20enemigo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enemies/walker/walker.gd | 49 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/enemies/walker/walker.gd b/enemies/walker/walker.gd index 010ae4d..5c35d43 100644 --- a/enemies/walker/walker.gd +++ b/enemies/walker/walker.gd @@ -70,6 +70,19 @@ enum AttackState { ## during its windup useful instead of forcing an unavoidable damage trade. @export var hit_stun_duration: float = 0.18 +## Strength of the knockback applied per point of damage. The final push is +## divided by the enemy's max health, so tougher enemies move less. +@export var knockback_strength: float = 500.0 + +## How long the knockback impulse lasts before friction brings the enemy to a halt. +@export var knockback_duration: float = 0.4 + +## Damage threshold to trigger a longer stun (e.g. a fully charged special attack). +@export_range(0, 100, 1) var stun_damage_threshold: int = 5 + +## Stun duration when the received damage exceeds the threshold. +@export var strong_hit_stun_duration: float = 2.0 + # ============================================================================ # RESPAWN @@ -131,6 +144,9 @@ var target: Node2D ## Prevents one sweep from damaging the same target once per physics frame. var attack_hit_targets: Dictionary = {} +## Timer for the knockback impulse applied when the enemy is hit. +var knockback_timer: float = 0.0 + ## Floating damage numbers shown above the enemy when it takes damage. ## Each entry: { text: String, local_pos: Vector2, timer: float } var _damage_texts: Array = [] @@ -176,11 +192,18 @@ func _physics_process(delta: float) -> void: queue_redraw() return - # Being hit pauses both movement and attack for only a few frames. The + # Being hit pauses both movement and attack. While the knockback impulse + # lasts the enemy is pushed back, then friction brings it to a halt. The # cooldown keeps running, so interrupting an attack does not make the enemy # immediately start another one. if hit_stun_timer > 0.0: - velocity.x = 0.0 + if knockback_timer > 0.0: + knockback_timer = max(knockback_timer - delta, 0.0) + var fade: float = knockback_timer / knockback_duration if knockback_duration > 0.0 else 0.0 + velocity.x = move_toward(velocity.x, 0.0, knockback_strength * delta * (1.0 - fade + 0.1)) + else: + velocity.x = move_toward(velocity.x, 0.0, knockback_strength * delta) + move_and_slide() queue_redraw() return @@ -421,8 +444,25 @@ func take_damage(amount: int, source_position: Vector2) -> void: # Light enemies are interruptible. This makes a well-timed player attack a # defensive option and avoids mandatory damage trades at close range. _interrupt_attack() - hit_stun_timer = hit_stun_duration - velocity.x = 0.0 + + # Knockback: stronger hits push harder, tougher enemies (more max health) + # resist the push. Direction is away from the damage source. + var knockback_dir: float = signf(global_position.x - source_position.x) + if knockback_dir == 0.0: + knockback_dir = 1.0 + + var knockback_force: float = float(amount) * knockback_strength / float(max_health) + velocity.x = knockback_dir * knockback_force + velocity.y = -180.0 + + knockback_timer = knockback_duration + + # Stun: normal hits use the brief hit stun; very strong hits (e.g. a fully + # charged special attack) trigger a longer stun. + if amount >= stun_damage_threshold: + hit_stun_timer = max(hit_stun_timer, strong_hit_stun_duration) + else: + hit_stun_timer = max(hit_stun_timer, hit_stun_duration) var reaction_direction: float = signf(source_position.x - global_position.x) if reaction_direction != 0.0: @@ -456,6 +496,7 @@ func _respawn() -> void: attack_phase_timer = 0.0 attack_cooldown_timer = 0.0 hit_stun_timer = 0.0 + knockback_timer = 0.0 attack_hit_targets.clear() attack_direction = facing_direction _reset_attack_hitbox_position() -- 2.54.0 From 37206548e13b7ec6a374fe5d6863907d08170244 Mon Sep 17 00:00:00 2001 From: Diego De la Viuda Llorente Date: Fri, 16 Oct 2026 13:16:44 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9BFIX:=20Error=20en=20el=20draw?= =?UTF-8?q?=20del=20enemigo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enemies/walker/walker.gd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/enemies/walker/walker.gd b/enemies/walker/walker.gd index 5c35d43..3430d40 100644 --- a/enemies/walker/walker.gd +++ b/enemies/walker/walker.gd @@ -609,10 +609,10 @@ func _draw_enemy_health_bar() -> void: # Draws floating damage numbers that drift upward and fade out. func _draw_damage_texts() -> void: + var font: Font = ThemeDB.get_default_theme().get_font("font", "Label") + if font == null: + return + for entry in _damage_texts: var alpha: float = clamp(entry.timer, 0.0, 1.0) - draw_string( - entry.local_pos, - entry.text, - Color(1, 1, 1, alpha) - ) + draw_string(font, entry.local_pos, entry.text, Color(1, 1, 1, alpha)) -- 2.54.0 From 80d550b6faf9056e11221f0bc35102de8143eb83 Mon Sep 17 00:00:00 2001 From: Diego De la Viuda Llorente Date: Fri, 16 Oct 2026 13:22:50 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=90=9BFIX:=20Reparada=20la=20funcion?= =?UTF-8?q?=20draw=5Fstring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enemies/walker/walker.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enemies/walker/walker.gd b/enemies/walker/walker.gd index 3430d40..77edcaa 100644 --- a/enemies/walker/walker.gd +++ b/enemies/walker/walker.gd @@ -615,4 +615,4 @@ func _draw_damage_texts() -> void: for entry in _damage_texts: var alpha: float = clamp(entry.timer, 0.0, 1.0) - draw_string(font, entry.local_pos, entry.text, Color(1, 1, 1, alpha)) + draw_string(font, entry.local_pos, entry.text, modulate=Color(1, 1, 1, alpha)) -- 2.54.0 From f33ab4e183dc3d32d2ce2a41e34cd3eb5a743119 Mon Sep 17 00:00:00 2001 From: Diego De la Viuda Llorente Date: Fri, 16 Oct 2026 13:24:57 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9BFIX:=20Reparada=20la=20funcion?= =?UTF-8?q?=20draw=5Fstring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enemies/walker/walker.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enemies/walker/walker.gd b/enemies/walker/walker.gd index 77edcaa..fccf8c2 100644 --- a/enemies/walker/walker.gd +++ b/enemies/walker/walker.gd @@ -615,4 +615,4 @@ func _draw_damage_texts() -> void: for entry in _damage_texts: var alpha: float = clamp(entry.timer, 0.0, 1.0) - draw_string(font, entry.local_pos, entry.text, modulate=Color(1, 1, 1, alpha)) + draw_string(font, entry.local_pos, entry.text, 0, -1, 16, Color(1, 1, 1, alpha)) -- 2.54.0