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

+77 -50
View File
@@ -1,79 +1,106 @@
extends Node2D
## Señal que se emite cuando el jugador alcanza el final del nivel.
## Android test course: 17 stations / 17 different guaranteed items.
## Encounters are configured in the scene, not spawned by code, so designers can
## freely move a station or switch its drop in the Godot inspector.
signal level_completed
const TEST_ITEM_COUNT: int = 17
const LEVEL_WIDTH: int = 8500
const FINISH_RESTART_SECONDS: float = 8.0
@onready var player: Node2D = $Player
@onready var message_label: Label = $MessageLabel
@onready var test_enemies: Node2D = $TestEnemies
@onready var status_label: Label = $TestHUD/Overlay/Status
@onready var finish_message: Label = $TestHUD/Overlay/FinishMessage
# Colores temporales de cada plataforma. Se pueden cambiar por texturas más tarde.
var platform_colors: Dictionary = {
"Floor": Color(0.2, 0.7, 0.2, 1.0), # Verde (suelo)
"Platform1": Color(0.4, 0.6, 1.0, 1.0), # Azul
"Platform2": Color(1.0, 0.4, 0.4, 1.0), # Rojo
"Platform3": Color(1.0, 1.0, 0.4, 1.0), # Amarillo
}
var victory_timer: float = 0.0
var collected_items: Dictionary = {} # PickupData.id -> true; count each only once
var showing_victory: bool = false
var victory_timer: float = 0.0
func _ready() -> void:
message_label.visible = false
# Zona de final del nivel (meta).
var finish: Area2D = $FinishZone
if finish:
finish.body_entered.connect(_on_finish_entered)
# Zona de muerte (caer fuera del nivel).
var death: Area2D = $DeathZone
if death:
death.body_entered.connect(_on_death_entered)
# Cuando el jugador muere, el nivel se recarga solo (player.gd ya lo hace).
if player.has_signal("died"):
player.died.connect(_on_player_died)
finish_message.visible = false
# Player Camera2D sets its own provisional limit (4000) in _ready.
# Override it here, after child _ready, for the long Android route.
var camera: Camera2D = player.get_node("Camera2D") as Camera2D
camera.limit_right = LEVEL_WIDTH
$FinishZone.body_entered.connect(_on_finish_entered)
$DeathZone.body_entered.connect(_on_death_entered)
player.connect(&"pickup_collected", _on_pickup_collected)
_update_status()
func _process(delta: float) -> void:
if showing_victory:
victory_timer += delta
if victory_timer >= 3.0:
if victory_timer >= FINISH_RESTART_SECONDS:
get_tree().reload_current_scene()
return
_update_status()
func _update_status() -> void:
# Each station has one enemy and an assigned pickup. Look ahead to the first
# living enemy so the player knows what to expect without opening a menu.
var next_item: String = "FIN DEL RECORRIDO"
for enemy in test_enemies.get_children():
if bool(enemy.get("is_dead")):
continue
var enemy_body: Node2D = enemy as Node2D
if enemy_body.position.x < player.position.x - 165.0:
continue
var data: PickupData = enemy.get("guaranteed_drop") as PickupData
if data != null:
next_item = data.display_name
break
status_label.text = "LAB THRASH %02d / %02d recogidos\nSIGUIENTE: %s" % [
collected_items.size(), TEST_ITEM_COUNT, next_item
]
func _on_pickup_collected(data: PickupData) -> void:
# A heal at full HP or a charge item with a full meter isn't consumed and
# doesn't count. The object remains on the floor for later collection.
collected_items[data.id] = true
_update_status()
func _on_finish_entered(body: Node2D) -> void:
if body != player:
if body != player or showing_victory:
return
showing_victory = true
message_label.text = "¡NIVEL COMPLETADO!"
message_label.visible = true
level_completed.emit()
finish_message.text = "FIN DEL LAB!\nObjetos recogidos: %d / %d\nReinicio en 8 s" % [
collected_items.size(), TEST_ITEM_COUNT
]
finish_message.visible = true
func _on_death_entered(body: Node2D) -> void:
if body != player:
return
# Caer al vacío mata al jugador y recarga el nivel.
if body.has_method("take_damage"):
if body == player and body.has_method("take_damage"):
body.take_damage(9999, body.global_position)
func _on_player_died() -> void:
# El nivel se recarga automáticamente desde player.gd.
pass
# Dibuja las plataformas con colores sólidos para que se vean en juego.
# Esto es solo temporal: se reemplazará por sprites/texturas cuando haya arte.
func _draw() -> void:
var world: Node = $World
for child in world.get_children():
if child is CollisionShape2D:
var shape: Shape2D = child.shape
if shape is RectangleShape2D:
var rect: Rect2 = Rect2(child.position - shape.size / 2.0, shape.size)
var color: Color = platform_colors.get(child.name, Color(0.5, 0.5, 0.5, 1.0))
draw_rect(rect, color, true)
draw_rect(rect, Color(1, 1, 1, 0.3), false, 2.0)
# Temporary coloured geometry; collision shapes are the single source of
# truth for position and dimensions, so the visuals cannot desynchronise.
for child in $World.get_children():
if not child is CollisionShape2D:
continue
var collision: CollisionShape2D = child as CollisionShape2D
var rectangle: RectangleShape2D = collision.shape as RectangleShape2D
if rectangle == null:
continue
var color: Color = Color(0.32, 0.57, 0.79)
if collision.name == "Floor":
color = Color(0.20, 0.40, 0.25)
elif collision.name.begins_with("High"):
color = Color(0.68, 0.39, 0.76)
var rect: Rect2 = Rect2(collision.position - rectangle.size / 2.0, rectangle.size)
draw_rect(rect, color, true)
draw_rect(rect, Color(0.93, 0.94, 1.0, 0.6), false, 2.0)