breadwinner/scenes/player/player_properties.gd
Balogh Krisztián 4869dcc3de big update, many changes
addefd some sound elements
changed the spatialaudio3d addon back so it it sounding okay
2026-07-30 01:44:27 +02:00

62 lines
1.4 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 selected_item: int = 0
var stamina_recharge: bool = true
var inventory: Array[PackedScene] = []
signal selected_item_changed
func next_item():
if selected_item + 1 > INVENTORY_MAX - 1:
selected_item = 0
else:
selected_item += 1
select_item(selected_item)
func prev_item():
if selected_item - 1 < 0:
selected_item = INVENTORY_MAX - 1
else:
selected_item -= 1
select_item(selected_item)
func select_item(index:int):
selected_item = index
emit_signal("selected_item_changed")
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:
select_item(0)
func _process(delta: float) -> void:
if stamina_recharge:
stamina = move_toward(stamina, 100, .5)
if Input.is_action_just_pressed("next_item"):
next_item()
if Input.is_action_just_pressed("prev_item"):
prev_item()
func _input(event: InputEvent) -> void:
if Input.is_action_just_pressed("select_item_1"):
select_item(0)
if Input.is_action_just_pressed("select_item_2"):
select_item(1)
if Input.is_action_just_pressed("select_item_3"):
select_item(2)