Nivel de prueba reimplementado

This commit is contained in:
Diego De la Viuda Llorente committed 2026-10-21 10:56:11 +02:00
1 parent 8fc8925151
commit 1e70a99224
24 files changed
+2384 -164

No files matched your search

+49 -27
View File
@@ -91,18 +91,26 @@ enum AttackState {
@export_category("Drops")
## Table defining what pickups can drop on death (by chance).
## Default weighted drops for normal encounters.
@export var drop_table: PickupDropTable
@export_category("Respawn")
## Optional fixed drop, used by the Level 01 test route. When assigned, this
## object drops with 100% probability INSTEAD of the random table.
@export var guaranteed_drop: PickupData
@export_category("Respawn")
## Enough downtime to make defeating an enemy meaningful before it comes back.
## A value of 0 disables respawn (one enemy = one test item).
@export var respawn_delay: float = 5.0
## Limits how far the enemy may chase from its spawn point; 0 = unrestricted.
## Small limits keep independent testing encounters from piling up.
@export var chase_radius: float = 0.0
## Only used to describe enemy variants in test HUDs.
@export var enemy_display_name: String = "Walker"
# ============================================================================
# DEBUG
@@ -130,6 +138,7 @@ enum AttackState {
@onready var attack_collision: CollisionShape2D = $AttackHitbox/CollisionShape2D
@onready var floor_probe: RayCast2D = $FloorProbe
@onready var visibility_notifier: VisibleOnScreenNotifier2D = $VisibleOnScreenNotifier2D
@onready var visual: Sprite2D = $Visual
# ============================================================================
@@ -263,6 +272,8 @@ func _update_facing() -> void:
if attack_state == AttackState.IDLE:
_reset_attack_hitbox_position()
# The five variants share one collision box and AI, but use different sprites.
visual.flip_h = facing_direction < 0.0
# ============================================================================
@@ -288,6 +299,13 @@ func _update_idle_behaviour() -> void:
func _chase_target() -> void:
# Limit chasing to the current testing station when chase_radius is set.
# Going back towards the spawn point is always allowed.
var distance_from_spawn: float = global_position.x - spawn_position.x
if chase_radius > 0.0 and absf(distance_from_spawn) >= chase_radius and signf(distance_from_spawn) == facing_direction:
velocity.x = 0.0
return
# Do not blindly walk off a platform while chasing. Proper pathfinding is
# intentionally postponed until levels actually require it.
if is_on_floor() and not floor_probe.is_colliding():
@@ -489,15 +507,18 @@ func _die() -> void:
is_dead = true
died.emit()
if drop_table != null:
var drops = DROP_MANAGER.roll_drop(drop_table)
if not drops.is_empty():
var parent := get_tree().current_scene
if parent == null:
parent = get_tree().root.get_child(get_tree().root.get_child_count() - 1)
if parent == null:
parent = get_tree().root
DROP_MANAGER.spawn_drops(drops, parent, global_position)
# Test encounters always drop their assigned item, including the two items
# absent from the normal Walker table. Other levels keep their random loot.
var drops: Array[PickupData] = []
if guaranteed_drop != null:
drops.append(guaranteed_drop)
elif drop_table != null:
drops = DROP_MANAGER.roll_drop(drop_table)
if not drops.is_empty():
var parent: Node = get_tree().current_scene
if parent == null:
parent = get_tree().root
DROP_MANAGER.spawn_drops(drops, parent, global_position)
velocity = Vector2.ZERO
visible = false
@@ -508,8 +529,9 @@ func _die() -> void:
hurtbox_collision.set_deferred("disabled", true)
attack_collision.set_deferred("disabled", true)
await get_tree().create_timer(respawn_delay).timeout
_respawn()
if respawn_delay > 0.0:
await get_tree().create_timer(respawn_delay).timeout
_respawn()
func _respawn() -> void:
@@ -544,19 +566,24 @@ func _respawn() -> void:
# ============================================================================
func _draw() -> void:
# The enemy has no sprite yet. This neutral block makes the actual entity
# visible independently from the debug overlays.
_draw_rectangle_collision(
body_collision,
Color(0.18, 0.18, 0.20, 0.90),
Color(0.85, 0.85, 0.90, 1.0)
)
# Retain a fallback body if an imported sprite is missing.
if visual.texture == null:
_draw_rectangle_collision(
body_collision,
Color(0.18, 0.18, 0.20, 0.90),
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()
# Orange windup is important gameplay feedback, not a debug hitbox.
# Keep it visible on Android even when red collision overlays are disabled.
if attack_state == AttackState.WINDUP:
_draw_attack_telegraph()
if not show_debug_hitboxes:
return
@@ -567,11 +594,6 @@ func _draw() -> void:
Color(1.0, 0.05, 0.05, 0.55)
)
# Windup: preview the full sweep in orange. It is explicitly NOT dangerous
# yet, so the different colour makes the reaction window easy to understand.
if attack_state == AttackState.WINDUP:
_draw_attack_telegraph()
# Active attack: draw the real moving physics hitbox in strong red.
if attack_state == AttackState.ACTIVE:
_draw_rectangle_collision(