added player Finite State Machine

This commit is contained in:
2025-07-19 22:08:07 +10:00
parent 4a26cf0ddb
commit d2dc74d533
39 changed files with 496 additions and 376 deletions

66
PCs/FSM/carding_state.gd Normal file
View File

@@ -0,0 +1,66 @@
class_name CardingState
extends HeroState
@export var swap_state: HeroState
func enter_state() -> void:
hero.set_card_elements_visibility(true)
hero.left_hand.visible = true
hero.carding_tool.enabled = true
func exit_state() -> void:
hero.set_card_elements_visibility(false)
hero.left_hand.visible = false
hero.carding_tool.enabled = false
func process_state(_delta: float) -> void:
hero.check_world_button()
if Input.is_action_just_pressed("Interact"):
hero.carding_tool.interact()
if Input.is_action_just_pressed("Primary Fire"):
hero.equip_weapon(0)
if Input.is_action_just_pressed("Secondary Fire"):
hero.equip_weapon(1)
if Input.is_action_just_pressed("Select Next Card") and hero.hand.size > 1:
hero.increment_selected()
hero.swap_card_audio.play()
if Input.is_action_just_pressed("Select Previous Card") and hero.hand.size > 1:
hero.decrement_selected()
hero.swap_card_audio.play()
if Input.is_action_just_pressed("Equip 1"):
swap_to_slot(1)
if Input.is_action_just_pressed("Equip 2"):
swap_to_slot(2)
if Input.is_action_just_pressed("Equip 3"):
swap_to_slot(3)
if Input.is_action_just_pressed("Equip 4"):
swap_to_slot(4)
if Input.is_action_just_pressed("Equip 5"):
swap_to_slot(5)
if Input.is_action_just_pressed("Equip 6"):
swap_to_slot(6)
if Input.is_action_just_pressed("Equip 7"):
swap_to_slot(7)
if Input.is_action_just_pressed("Equip 8"):
swap_to_slot(8)
if Input.is_action_just_pressed("Equip 9"):
swap_to_slot(9)
if Input.is_action_just_pressed("Equip 10"):
swap_to_slot(10)
if Input.is_action_just_pressed("Swap Weapons"):
state_changed.emit(swap_state)
if Input.is_action_pressed("Ready"):
if hero.ready_state:
hero.unready_self()
else:
hero.ready_self()
func swap_to_slot(num: int) -> void:
if hero.unique_cards.size() >= num:
hero.hand_selected_index = num - 1
hero.swap_card_audio.play()
hero.update_selected_box()