somewhat working console, fully developed from the ground up some things work with it, but its still pretty buggy currently runs on global autoload because its the easiest way rn, later on have to change it so that only if the player is in the game and console is enabled it can be toggled
51 lines
1.3 KiB
GDScript
51 lines
1.3 KiB
GDScript
extends Node
|
|
|
|
@export_category("Inventory")
|
|
@export var INVENTORY_MAX = 3 ##max number of items that can be in the player's inventory
|
|
@export var INVENTORY_ITEMS: Array = [] ##the items in the player's inventory
|
|
|
|
var stamina: float = 100.0
|
|
var flashlight_power: float = 100.0
|
|
var selected_item: int = 0
|
|
var stamina_recharge: bool = true
|
|
var inventory: Array[PackedScene] = [null,null]
|
|
|
|
@onready var ui: Control = %PlayerUi
|
|
@onready var flashlight: SpotLight3D = %Flashlight
|
|
|
|
func next_item():
|
|
if selected_item + 1 > len(inventory) - 1:
|
|
selected_item = 0
|
|
else:
|
|
selected_item += 1
|
|
select_item(selected_item)
|
|
|
|
func prev_item():
|
|
if selected_item - 1 < 0:
|
|
selected_item = len(inventory) - 1
|
|
else:
|
|
selected_item -= 1
|
|
select_item(selected_item)
|
|
|
|
func select_item(index:int):
|
|
selected_item = index
|
|
ui.select_item(index)
|
|
|
|
func get_selected_item() -> PackedScene:
|
|
return inventory[selected_item]
|
|
|
|
func stamina_recharge_off():
|
|
stamina_recharge = false
|
|
|
|
func _on_stamina_reset_timeout() -> void:
|
|
stamina_recharge = true
|
|
|
|
func _ready() -> void:
|
|
await get_tree().create_timer(0.1).timeout.connect(func (): select_item(0))
|
|
|
|
func _process(delta: float) -> void:
|
|
if stamina_recharge:
|
|
stamina = move_toward(stamina, 100, .5)
|
|
if flashlight.visible:
|
|
flashlight_power = move_toward(flashlight_power, 0, .2)
|
|
|