♻️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
@@ -4,6 +4,7 @@ class_name DropManager
|
||||
const PICKUP_SCENE := preload("res://pickups/pickup.tscn")
|
||||
|
||||
|
||||
## Sortea una cantidad de objetos sin repetir entradas, usando pesos no negativos.
|
||||
static func roll_drop(drop_table: PickupDropTable) -> Array[PickupData]:
|
||||
var result: Array[PickupData] = []
|
||||
if drop_table == null:
|
||||
@@ -44,10 +45,10 @@ static func roll_drop(drop_table: PickupDropTable) -> Array[PickupData]:
|
||||
return result
|
||||
|
||||
|
||||
## Instancia recompensas desde coordenadas globales y difiere su entrada al arbol.
|
||||
static func spawn_drops(drops_data: Array[PickupData], parent: Node, position: Vector2) -> void:
|
||||
# Death can happen inside a physics collision callback. Adding a new Area2D
|
||||
# immediately at that point is unsafe: defer its entry into the scene tree.
|
||||
# Set its local position first so it never briefly enters at the origin.
|
||||
# La muerte puede ocurrir dentro de un contacto fisico. Se difiere la entrada
|
||||
# del nuevo Area2D al arbol y se prepara antes su posicion local para evitar aparecer en el origen.
|
||||
var local_position: Vector2 = position
|
||||
if parent is Node2D:
|
||||
local_position = (parent as Node2D).to_local(position)
|
||||
|
||||
+53
-10
@@ -1,16 +1,30 @@
|
||||
@tool
|
||||
extends Area2D
|
||||
class_name Pickup
|
||||
|
||||
signal picked_up(pickup: Pickup, data: PickupData)
|
||||
|
||||
# Enemies leave their reward on screen briefly. A player who touches it during
|
||||
# that interval must still receive it, even if they keep running.
|
||||
# Los drops permanecen visibles brevemente antes de poder recogerse.
|
||||
# Se recuerda al jugador que los toque durante esa espera, aunque continue corriendo.
|
||||
const DROP_COLLECTION_DELAY_SECONDS: float = 0.75
|
||||
|
||||
@export var pickup_data: PickupData
|
||||
## Recurso compartido de efecto; para cambiar solo esta instancia, hazlo unico.
|
||||
@export var pickup_data: PickupData:
|
||||
set(value):
|
||||
if pickup_data != null and pickup_data.changed.is_connected(_update_preview):
|
||||
pickup_data.changed.disconnect(_update_preview)
|
||||
pickup_data = value
|
||||
if pickup_data != null and not pickup_data.changed.is_connected(_update_preview):
|
||||
pickup_data.changed.connect(_update_preview)
|
||||
if is_inside_tree():
|
||||
call_deferred("_update_preview")
|
||||
## Espera antes de permitir la recogida; los objetos colocados usan cero.
|
||||
@export var collection_delay_seconds: float = 0.0
|
||||
## Aceleracion de caida del objeto; conserva el comportamiento previo.
|
||||
@export var fall_speed: float = 150.0
|
||||
## Amplitud vertical de la oscilacion al apoyarse en el suelo.
|
||||
@export var bob_amplitude: float = 4.0
|
||||
## Velocidad angular de esa oscilacion.
|
||||
@export var bob_speed: float = 3.0
|
||||
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
@@ -18,14 +32,18 @@ var time: float = 0.0
|
||||
var start_y: float = 0.0
|
||||
var grounded: bool = false
|
||||
var _can_collect: bool = false
|
||||
var _pending_collector: Node2D # Player who crossed the pickup during its delay.
|
||||
var _pending_collector: Node2D # Jugador que toco el objeto durante la espera.
|
||||
|
||||
@onready var label: Label = $Label
|
||||
@onready var sprite: Sprite2D = $Sprite2D
|
||||
@onready var placeholder: ColorRect = $Sprite2D/ColorRect
|
||||
|
||||
|
||||
## Prepara la vista previa; solo en partida activa la recogida y sus senales.
|
||||
func _ready() -> void:
|
||||
_update_preview()
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
add_to_group("pickup")
|
||||
body_entered.connect(_on_body_entered)
|
||||
|
||||
@@ -47,20 +65,23 @@ func _ready() -> void:
|
||||
_can_collect = true
|
||||
|
||||
|
||||
## Habilita el drop y resuelve un contacto que hubiera ocurrido durante la espera.
|
||||
func _enable_collection_after_delay() -> void:
|
||||
await get_tree().create_timer(collection_delay_seconds).timeout
|
||||
if not is_inside_tree():
|
||||
return
|
||||
_can_collect = true
|
||||
|
||||
# A body_entered signal received during the delay is not lost. Crossing a
|
||||
# spawning item counts as touching it, even if the player is now elsewhere.
|
||||
# No se pierde un contacto recibido durante la espera: atravesar el objeto cuenta como haberlo tocado.
|
||||
if is_instance_valid(_pending_collector):
|
||||
_on_body_entered(_pending_collector)
|
||||
_pending_collector = null
|
||||
|
||||
|
||||
## Hace caer/flotar el objeto y reintenta aplicar efectos mientras el jugador lo toca.
|
||||
func _physics_process(delta: float) -> void:
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
time += delta
|
||||
if not grounded:
|
||||
velocity.y += fall_speed * delta
|
||||
@@ -72,9 +93,8 @@ func _physics_process(delta: float) -> void:
|
||||
else:
|
||||
position.y = start_y + sin(time * bob_speed) * bob_amplitude
|
||||
|
||||
# body_entered only fires at the start of a contact. Rechecking overlaps
|
||||
# also handles moving pickups and effects that were unusable on first touch
|
||||
# (e.g. a heal while HP was full, then the player takes damage).
|
||||
# body_entered solo avisa al comenzar el contacto. Revisar solapamientos
|
||||
# permite recoger un objeto cuando pasa a ser util sin exigir salir y volver a entrar.
|
||||
if pickup_data != null and not is_queued_for_deletion():
|
||||
for body in get_overlapping_bodies():
|
||||
_on_body_entered(body)
|
||||
@@ -82,6 +102,7 @@ func _physics_process(delta: float) -> void:
|
||||
break
|
||||
|
||||
|
||||
## Sonda de suelo sobre la capa World; los objetos son areas, no cuerpos fisicos.
|
||||
func is_on_floor() -> bool:
|
||||
var space = get_world_2d().direct_space_state
|
||||
var params = PhysicsRayQueryParameters2D.create(global_position, global_position + Vector2(0, 12))
|
||||
@@ -90,6 +111,7 @@ func is_on_floor() -> bool:
|
||||
return result.size() > 0
|
||||
|
||||
|
||||
## Consume el objeto solo cuando Player confirma que se ha aplicado su efecto.
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if pickup_data == null or is_queued_for_deletion():
|
||||
return
|
||||
@@ -104,7 +126,28 @@ func _on_body_entered(body: Node2D) -> void:
|
||||
picked_up.emit(self, pickup_data)
|
||||
queue_free()
|
||||
elif pickup_data.effect_type == "heal":
|
||||
# This is not a collision failure: the player already has full HP.
|
||||
# No es un fallo de colision: el jugador ya tiene la vida completa.
|
||||
label.text = "%s\n(HP LLENO)" % pickup_data.display_name
|
||||
elif pickup_data.effect_type == "special_charge":
|
||||
label.text = "%s\n(ESPECIAL LLENO)" % pickup_data.display_name
|
||||
|
||||
|
||||
## Actualiza exclusivamente la presentacion; nunca consume objetos en el editor.
|
||||
func _update_preview() -> void:
|
||||
if not is_inside_tree() or not has_node("Label"):
|
||||
return
|
||||
var preview_label: Label = $Label
|
||||
var preview_sprite: Sprite2D = $Sprite2D
|
||||
var preview_placeholder: ColorRect = $Sprite2D/ColorRect
|
||||
preview_label.text = pickup_data.display_name if pickup_data != null else "SIN DATOS"
|
||||
preview_sprite.texture = pickup_data.icon if pickup_data != null else null
|
||||
preview_placeholder.visible = preview_sprite.texture == null
|
||||
preview_placeholder.color = pickup_data.color if pickup_data != null else Color.MAGENTA
|
||||
update_configuration_warnings()
|
||||
|
||||
|
||||
## Avisa en el arbol del editor cuando falta el recurso de datos.
|
||||
func _get_configuration_warnings() -> PackedStringArray:
|
||||
if pickup_data == null:
|
||||
return PackedStringArray(["Asigna Pickup Data o arrastra una escena de pickups/variants."])
|
||||
return PackedStringArray()
|
||||
+15
-5
@@ -1,18 +1,28 @@
|
||||
@tool
|
||||
extends Resource
|
||||
class_name PickupData
|
||||
|
||||
@export_category("Identity")
|
||||
@export var id: StringName = &"pickup"
|
||||
@export var display_name: String = "Item"
|
||||
@export var display_name: String = "Item":
|
||||
set(value):
|
||||
display_name = value
|
||||
emit_changed()
|
||||
@export_multiline var description: String = ""
|
||||
|
||||
@export_category("Visuals")
|
||||
@export var icon: Texture2D
|
||||
@export var color: Color = Color(1.0, 0.7, 0.2)
|
||||
@export var icon: Texture2D:
|
||||
set(value):
|
||||
icon = value
|
||||
emit_changed()
|
||||
@export var color: Color = Color(1.0, 0.7, 0.2):
|
||||
set(value):
|
||||
color = value
|
||||
emit_changed()
|
||||
|
||||
@export_category("Effect")
|
||||
## heal and special_charge are instant; shield absorbs one hit; others expire.
|
||||
## value is an absolute amount for heal/charge, a fractional bonus for timed buffs.
|
||||
## heal y special_charge son instantaneos; shield absorbe golpes; las demas mejoras caducan.
|
||||
## Value expresa cantidad absoluta para vida/carga y fraccion adicional para mejoras temporales.
|
||||
@export_enum("heal", "speed_boost", "damage_boost", "special_charge", "shield", "damage_reduction", "jump_boost", "air_damage_boost") var effect_type: String = "heal"
|
||||
@export var value: float = 0.0
|
||||
@export var duration: float = 0.0
|
||||
@@ -1,5 +1,7 @@
|
||||
extends Resource
|
||||
class_name PickupDrop
|
||||
|
||||
## Recurso que se entregara si se selecciona esta entrada.
|
||||
@export var pickup: PickupData
|
||||
## Peso relativo, no porcentaje. Cero excluye la entrada del sorteo normal.
|
||||
@export_range(0.0, 100.0, 0.1) var weight: float = 1.0
|
||||
@@ -1,7 +1,11 @@
|
||||
extends Resource
|
||||
class_name PickupDropTable
|
||||
|
||||
## Entradas disponibles; un mismo sorteo no repite la misma entrada.
|
||||
@export var drops: Array[PickupDrop] = []
|
||||
## Probabilidad de efectuar un sorteo: cero nunca, uno siempre.
|
||||
@export_range(0.0, 1.0) var drop_chance: float = 0.5
|
||||
## Cantidad minima solicitada, limitada por las entradas disponibles.
|
||||
@export_range(0, 10, 1) var min_drops: int = 1
|
||||
## Cantidad maxima solicitada; debe ser mayor o igual que Min Drops.
|
||||
@export_range(0, 10, 1) var max_drops: int = 1
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/amplificador_11.tres" id="data"]
|
||||
[node name="Amplifier11" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/pua_apocalipsis.tres" id="data"]
|
||||
[node name="ApocalypsePick" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/beer.tres" id="data"]
|
||||
[node name="Beer" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/coffee.tres" id="data"]
|
||||
[node name="Coffee" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/casete_demo.tres" id="data"]
|
||||
[node name="DemoTape" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/pedal_distorsion.tres" id="data"]
|
||||
[node name="DistortionPedal" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/botas_doble_bombo.tres" id="data"]
|
||||
[node name="DoubleKickBoots" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/tupper_bateria.tres" id="data"]
|
||||
[node name="DrummerLunch" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/cinta_americana.tres" id="data"]
|
||||
[node name="DuctTape" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/lata_feedback.tres" id="data"]
|
||||
[node name="FeedbackCan" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/setlist_fin.tres" id="data"]
|
||||
[node name="FinalSetlist" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/pizza_post_bolo.tres" id="data"]
|
||||
[node name="PostShowPizza" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/bocata_roadie.tres" id="data"]
|
||||
[node name="RoadieSandwich" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/baqueta_sismica.tres" id="data"]
|
||||
[node name="SeismicDrumstick" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/muelles_stage.tres" id="data"]
|
||||
[node name="StageSprings" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/tapones_tecnico.tres" id="data"]
|
||||
[node name="TechnicianEarplugs" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
@@ -0,0 +1,5 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
[ext_resource type="PackedScene" path="res://pickups/pickup.tscn" id="base"]
|
||||
[ext_resource type="Resource" path="res://pickups/data/cuerda_titanio.tres" id="data"]
|
||||
[node name="TitaniumString" instance=ExtResource("base")]
|
||||
pickup_data = ExtResource("data")
|
||||
Reference in new issue
Block a user