breadwinner/scenes/player/player_properties.gd
Balogh Krisztián eb197412dd minor optimization and bit more mechanics
title says all.
still need to do the connection between the player.gd and its components
breathing sounds weird becausae for some reason it stops playing the audiostream when it shouldnt???????????????? im really confused
2026-07-29 13:52:14 +02:00

66 lines
1.5 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
@onready var ui_handler: Node = %UiHandler
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
ui_handler.update_inventory_ui()
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)