Merge pull request '➕ADD: vida y daño para debug al enemigo' (#7) from feature/ia_automated_test into main
Android Debug APK / build (push) Successful in 44s

Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
ankdev committed 2026-10-16 10:59:29 +00:00
commit 18b0ca30c2
1 file changed
+59
+59
View File
@@ -92,6 +92,10 @@ enum AttackState {
## The orange area during windup previews the complete attack sweep.
@export var show_debug_hitboxes: bool = true
## Shows the enemy health bar above its head and floating damage numbers when
## it is hit. Purely debug: can be disabled once final art and UI exist.
@export var show_debug_enemy_info: bool = true
# ============================================================================
# NODES
@@ -127,6 +131,10 @@ var target: Node2D
## Prevents one sweep from damaging the same target once per physics frame.
var attack_hit_targets: Dictionary = {}
## Floating damage numbers shown above the enemy when it takes damage.
## Each entry: { text: String, local_pos: Vector2, timer: float }
var _damage_texts: Array = []
func _ready() -> void:
spawn_position = global_position
@@ -149,6 +157,7 @@ func _physics_process(delta: float) -> void:
return
_update_timers(delta)
_update_damage_texts(delta)
_apply_gravity(delta)
# The enemy deliberately does nothing until the camera has shown it once.
@@ -378,6 +387,15 @@ func _update_timers(delta: float) -> void:
hit_stun_timer = max(hit_stun_timer - delta, 0.0)
# Updates floating damage numbers: they drift upward and fade out over time.
func _update_damage_texts(delta: float) -> void:
for i in range(_damage_texts.size() - 1, -1, -1):
var entry: Dictionary = _damage_texts[i]
entry.timer = max(entry.timer - delta, 0.0)
entry.local_pos.y -= 40.0 * delta
if entry.timer <= 0.0:
_damage_texts.remove_at(i)
# ============================================================================
# DAMAGE AND RESPAWN
# ============================================================================
@@ -388,6 +406,14 @@ func take_damage(amount: int, source_position: Vector2) -> void:
current_health = max(current_health - amount, 0)
# Floating damage number (debug only).
if show_debug_enemy_info:
_damage_texts.append({
"text": str(amount),
"local_pos": Vector2(0, -25),
"timer": 1.0
})
if current_health == 0:
_die()
return
@@ -460,6 +486,11 @@ func _draw() -> void:
Color(0.85, 0.85, 0.90, 1.0)
)
# Enemy health bar and floating damage numbers (debug overlay).
if show_debug_enemy_info:
_draw_enemy_health_bar()
_draw_damage_texts()
if not show_debug_hitboxes:
return
@@ -516,3 +547,31 @@ func _draw_rectangle_collision(
var rect: Rect2 = Rect2(center - rectangle.size / 2.0, rectangle.size)
draw_rect(rect, fill_color, true)
draw_rect(rect, outline_color, false, 2.0)
# Draws a small horizontal health bar just above the enemy's head.
func _draw_enemy_health_bar() -> void:
var bar_width: float = 40.0
var bar_height: float = 5.0
var bar_pos: Vector2 = Vector2(-bar_width * 0.5, -48.0)
# Background.
draw_rect(Rect2(bar_pos, Vector2(bar_width, bar_height)), Color(0.2, 0.2, 0.2, 0.8), true)
# Fill.
var fill_ratio: float = current_health / max_health if max_health > 0 else 0.0
draw_rect(
Rect2(bar_pos, Vector2(bar_width * fill_ratio, bar_height)),
Color(0.85, 0.2, 0.2, 0.95),
true
)
# Border.
draw_rect(Rect2(bar_pos, Vector2(bar_width, bar_height)), Color(1, 1, 1, 0.6), false, 1.0)
# Draws floating damage numbers that drift upward and fade out.
func _draw_damage_texts() -> void:
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)
)