♻️REFACTOR: Mejoras en la viabilidad para desarrollo
This commit is contained in:
1 parent
5aba6c7b47
commit
fd0118d964
98 files changed
+5985
-3024
No files matched your search
+15
-46
@@ -1,22 +1,15 @@
|
||||
extends Node2D
|
||||
@tool
|
||||
extends LevelRoot
|
||||
|
||||
## Alpha de campo: recorrido urbano con suelo a distintas alturas, plataformas,
|
||||
## grupos de enemigos y objetos opcionales. Las posiciones y colisiones se editan
|
||||
## en level_02.tscn; este script solo dibuja las superficies y gestiona la meta.
|
||||
## en level_02.tscn; este script solo gestiona el progreso y la meta.
|
||||
## No interviene en los drops: los Walker usan su sistema habitual.
|
||||
|
||||
signal level_completed
|
||||
|
||||
const WORLD_WIDTH: int = 11000
|
||||
const FINISH_RESTART_SECONDS: float = 9.0
|
||||
|
||||
# El dibujo utiliza directamente los CollisionShape2D del escenario. Así no
|
||||
# hay una segunda lista de coordenadas visuales que pueda desincronizarse.
|
||||
const ASPHALT: Texture2D = preload("res://assets/city/asphalt.png")
|
||||
const CURB: Texture2D = preload("res://assets/city/curb.png")
|
||||
const WALKWAY: Texture2D = preload("res://assets/city/walkway.png")
|
||||
const BARRIER: Texture2D = preload("res://assets/city/barrier.png")
|
||||
|
||||
@onready var player: CharacterBody2D = $Player
|
||||
@onready var enemies: Node2D = $Enemies
|
||||
@onready var status_label: Label = $LevelHUD/Overlay/Status
|
||||
@@ -27,15 +20,11 @@ var completed: bool = false
|
||||
var _finish_timer: float = 0.0
|
||||
|
||||
|
||||
## Conecta meta y derrotas; LevelRoot aplica los limites de camara.
|
||||
func _ready() -> void:
|
||||
# Camera2D configura un límite provisional de 4000 en su propio _ready().
|
||||
# El nivel lo sustituye después de que el jugador haya entrado en el árbol.
|
||||
var camera: Camera2D = player.get_node("Camera2D") as Camera2D
|
||||
camera.limit_left = 0
|
||||
camera.limit_top = 0
|
||||
camera.limit_right = WORLD_WIDTH
|
||||
camera.limit_bottom = 1280
|
||||
|
||||
super._ready()
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
$FinishZone.body_entered.connect(_on_finish_entered)
|
||||
finish_message.visible = false
|
||||
for enemy: Node in enemies.get_children():
|
||||
@@ -44,7 +33,11 @@ func _ready() -> void:
|
||||
_update_status()
|
||||
|
||||
|
||||
## Actualiza el progreso o espera el reinicio tras completar la calle.
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
if completed:
|
||||
_finish_timer += delta
|
||||
if _finish_timer >= FINISH_RESTART_SECONDS:
|
||||
@@ -53,17 +46,20 @@ func _process(delta: float) -> void:
|
||||
_update_status()
|
||||
|
||||
|
||||
## Incrementa el contador de enemigos derrotados.
|
||||
func _on_enemy_died() -> void:
|
||||
defeated_enemies += 1
|
||||
|
||||
|
||||
## Calcula el sector segun los limites editables del nivel.
|
||||
func _update_status() -> void:
|
||||
var sector: int = clampi(int(player.global_position.x / (WORLD_WIDTH / 8.0)) + 1, 1, 8)
|
||||
var sector: int = clampi(int((player.position.x - camera_bounds.position.x) / (camera_bounds.size.x / 8.0)) + 1, 1, 8)
|
||||
status_label.text = "CALLE DEL FEEDBACK %02d/08\nKOs: %02d/%02d" % [
|
||||
sector, defeated_enemies, enemies.get_child_count()
|
||||
]
|
||||
|
||||
|
||||
## Muestra el resultado una sola vez al alcanzar la meta.
|
||||
func _on_finish_entered(body: Node2D) -> void:
|
||||
if body != player or completed:
|
||||
return
|
||||
@@ -73,30 +69,3 @@ func _on_finish_entered(body: Node2D) -> void:
|
||||
defeated_enemies, enemies.get_child_count()
|
||||
]
|
||||
finish_message.visible = true
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
# Tiling GPU: dos pequeños PNG para miles de unidades de calle.
|
||||
for collision: CollisionShape2D in $World/Ground.get_children():
|
||||
var bounds: Rect2 = _collision_rect(collision)
|
||||
if bounds.has_area():
|
||||
draw_texture_rect(ASPHALT, bounds, true)
|
||||
draw_texture_rect(CURB, Rect2(bounds.position.x, bounds.position.y, bounds.size.x, 24), true)
|
||||
|
||||
# Plataformas de una sola dirección: se atraviesan desde abajo, se aterriza
|
||||
# sobre ellas desde arriba y un segundo salto abre rutas opcionales.
|
||||
for collision: CollisionShape2D in $World/Walkways.get_children():
|
||||
var bounds: Rect2 = _collision_rect(collision)
|
||||
if bounds.has_area():
|
||||
draw_texture_rect(WALKWAY, bounds, true)
|
||||
|
||||
# Barreras visibles y sólidas; el jugador no puede abandonar el mapa.
|
||||
for wall_x: float in [0.0, WORLD_WIDTH - 48.0]:
|
||||
draw_texture_rect(BARRIER, Rect2(wall_x, 280.0, 48.0, 820.0), true)
|
||||
|
||||
|
||||
func _collision_rect(collision: CollisionShape2D) -> Rect2:
|
||||
var shape: RectangleShape2D = collision.shape as RectangleShape2D
|
||||
if shape == null:
|
||||
return Rect2()
|
||||
return Rect2(collision.position - shape.size * 0.5, shape.size)
|
||||
Reference in new issue
Block a user