player: handle gears on respawn

Use a preloaded scene to give the player the starting gear rather than
making a duplicate of the gear on spawn, and strip any gears from the
backpack on death.

Remove Gear from the editor scene tree and add it on respawn().
This commit is contained in:
Jeremy Baxter 2026-01-22 14:29:59 +13:00
parent d395bb6f26
commit 9b229e5d8f
2 changed files with 16 additions and 7 deletions

View file

@ -8,11 +8,12 @@ const gear_slots = ["1", "2", "3"]
@onready var spawn = Vector3(position)
var starting_gear = preload("res://gears/ball.tscn")
var health = 100
var suspended = false
var direction = Vector3.ZERO
var target_velocity = Vector3.ZERO
var initial_gear = null
func resize_ui():
var bpui_h = 200
@ -40,6 +41,12 @@ func die():
suspended = true
visible = false
$BackpackUI.visible = false
# strip gears
for gear in $Backpack.get_children():
gear.queue_free()
$Pivot/Container/Gear.queue_free()
$RespawnTimer.start()
message("Le gone")
@ -49,6 +56,12 @@ func respawn():
health = 100
visible = true
suspended = false
# add starting gear
var gear = starting_gear.instantiate()
$Pivot/Container.add_child(gear)
make_backpack_ui()
$BackpackUI.visible = true
# Backpack functions
@ -136,10 +149,9 @@ func move_player(x, z):
direction += camera_basis.x * x
func _ready():
initial_gear = $Pivot/Container/Gear.duplicate()
get_viewport().size_changed.connect(resize_ui)
resize_ui()
make_backpack_ui()
respawn()
func _physics_process(delta):
if suspended: