Feature/ia automated test #8

Merged
ankdev merged 4 commits from feature/ia_automated_test into main 2026-10-16 11:26:03 +00:00
+50 -9
View File
@@ -70,6 +70,19 @@ enum AttackState {
## during its windup useful instead of forcing an unavoidable damage trade. ## during its windup useful instead of forcing an unavoidable damage trade.
@export var hit_stun_duration: float = 0.18 @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 # RESPAWN
@@ -131,6 +144,9 @@ var target: Node2D
## Prevents one sweep from damaging the same target once per physics frame. ## Prevents one sweep from damaging the same target once per physics frame.
var attack_hit_targets: Dictionary = {} 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. ## Floating damage numbers shown above the enemy when it takes damage.
## Each entry: { text: String, local_pos: Vector2, timer: float } ## Each entry: { text: String, local_pos: Vector2, timer: float }
var _damage_texts: Array = [] var _damage_texts: Array = []
@@ -176,11 +192,18 @@ func _physics_process(delta: float) -> void:
queue_redraw() queue_redraw()
return 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 # cooldown keeps running, so interrupting an attack does not make the enemy
# immediately start another one. # immediately start another one.
if hit_stun_timer > 0.0: 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() move_and_slide()
queue_redraw() queue_redraw()
return 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 # Light enemies are interruptible. This makes a well-timed player attack a
# defensive option and avoids mandatory damage trades at close range. # defensive option and avoids mandatory damage trades at close range.
_interrupt_attack() _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) var reaction_direction: float = signf(source_position.x - global_position.x)
if reaction_direction != 0.0: if reaction_direction != 0.0:
@@ -456,6 +496,7 @@ func _respawn() -> void:
attack_phase_timer = 0.0 attack_phase_timer = 0.0
attack_cooldown_timer = 0.0 attack_cooldown_timer = 0.0
hit_stun_timer = 0.0 hit_stun_timer = 0.0
knockback_timer = 0.0
attack_hit_targets.clear() attack_hit_targets.clear()
attack_direction = facing_direction attack_direction = facing_direction
_reset_attack_hitbox_position() _reset_attack_hitbox_position()
@@ -568,10 +609,10 @@ func _draw_enemy_health_bar() -> void:
# Draws floating damage numbers that drift upward and fade out. # Draws floating damage numbers that drift upward and fade out.
func _draw_damage_texts() -> void: 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: for entry in _damage_texts:
var alpha: float = clamp(entry.timer, 0.0, 1.0) var alpha: float = clamp(entry.timer, 0.0, 1.0)
draw_string( draw_string(font, entry.local_pos, entry.text, 0, -1, 16, Color(1, 1, 1, alpha))
entry.local_pos,
entry.text,
Color(1, 1, 1, alpha)
)