32 lines
943 B
GDScript
32 lines
943 B
GDScript
extends HBoxContainer
|
|
|
|
@export var current_battery : TextureProgressBar
|
|
@export var battery_drain : float = 1
|
|
@export var starting_batteries : int = 3
|
|
var cb_value : float = 16
|
|
var extra_batteries : int
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
extra_batteries = starting_batteries -1
|
|
redraw_extra_batteries()
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
if cb_value <= 0:
|
|
extra_batteries -= 1
|
|
cb_value = 16
|
|
redraw_extra_batteries()
|
|
var thrust : float = Input.get_action_strength("thrust")
|
|
cb_value -= thrust * delta * battery_drain
|
|
current_battery.value = cb_value
|
|
|
|
func redraw_extra_batteries():
|
|
for i in range(get_children().size()):
|
|
if(i != 0):
|
|
get_child(i).queue_free()
|
|
|
|
for i in range(extra_batteries):
|
|
var new_extra = load("res://Prefabs/spare_battery.tscn").instantiate()
|
|
add_child(new_extra)
|