beta-1.3/restructure-files (#2)
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
33
Entities/Characters/Player/Scripts/States/base_state.gd
Normal file
33
Entities/Characters/Player/Scripts/States/base_state.gd
Normal file
@@ -0,0 +1,33 @@
|
||||
class_name BaseState
|
||||
extends Node
|
||||
|
||||
@export var state_machine: PlayerStateMachine
|
||||
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
push_error("Unimplemented Method: BaseState.GetName")
|
||||
return PlayerStateMachine.States.IDLE
|
||||
|
||||
|
||||
func GetAnimationBaseName() -> String:
|
||||
var state: String = PlayerStateMachine.States.keys()[GetStateEnum()]
|
||||
return state.to_lower()
|
||||
|
||||
|
||||
func Enter(_extra_parameters: Dictionary) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func Exit() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func Update(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func IsActive() -> bool:
|
||||
return state_machine.GetCurrentStateEnum() == GetStateEnum()
|
||||
|
||||
|
||||
func IsStateActionable() -> bool:
|
||||
return true
|
||||
@@ -0,0 +1 @@
|
||||
uid://cb57l5vpq5bee
|
||||
29
Entities/Characters/Player/Scripts/States/cutscene_state.gd
Normal file
29
Entities/Characters/Player/Scripts/States/cutscene_state.gd
Normal file
@@ -0,0 +1,29 @@
|
||||
extends BaseState
|
||||
class_name PlayerCutsceneState
|
||||
|
||||
@onready var interact_scanner: InteractScanner = $"../../../Marker2D/InteractScanner"
|
||||
|
||||
# Public Methods
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
return PlayerStateMachine.States.CUTSCENE
|
||||
|
||||
|
||||
func GetAnimationBaseName() -> String:
|
||||
return "idle"
|
||||
|
||||
|
||||
func Enter(_extra_parameters: Dictionary) -> void:
|
||||
print("Cutscene Started")
|
||||
interact_scanner.disable_interactions = true
|
||||
|
||||
|
||||
func Exit() -> void:
|
||||
interact_scanner.disable_interactions = false
|
||||
|
||||
|
||||
func OnCutsceneEnded() -> void:
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.IDLE)
|
||||
|
||||
|
||||
func IsStateActionable() -> bool:
|
||||
return false
|
||||
@@ -0,0 +1 @@
|
||||
uid://bnontuqj3cnom
|
||||
@@ -0,0 +1,37 @@
|
||||
extends BaseState
|
||||
|
||||
signal PlayerBeganDrawingBow
|
||||
|
||||
@export var strafing_speed := 35
|
||||
@export var movement_componenent: MovementComponent
|
||||
@export var body: CharacterBody2D
|
||||
|
||||
var used_item_action: String
|
||||
var animation_finished := false
|
||||
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
return PlayerStateMachine.States.DRAWING_BOW
|
||||
|
||||
|
||||
func Enter(extra_parameters: Dictionary) -> void:
|
||||
animation_finished = false
|
||||
used_item_action = extra_parameters.action_name
|
||||
PlayerBeganDrawingBow.emit()
|
||||
|
||||
|
||||
func Update(_delta: float) -> void:
|
||||
if !animation_finished:
|
||||
return
|
||||
|
||||
if !Input.is_action_pressed(used_item_action):
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.FIRING_ARROW)
|
||||
return
|
||||
|
||||
var movement_vector := movement_componenent.movement_vector
|
||||
if movement_vector != Vector2.ZERO:
|
||||
body.velocity = movement_vector * strafing_speed
|
||||
body.move_and_slide()
|
||||
|
||||
|
||||
func OnDrawingBowAnimationFinished() -> void:
|
||||
animation_finished = true
|
||||
@@ -0,0 +1 @@
|
||||
uid://bnp1vowmu15lg
|
||||
@@ -0,0 +1,31 @@
|
||||
extends BaseState
|
||||
class_name FiringArrowState
|
||||
|
||||
signal PlayerBeganFiringArrow
|
||||
signal ArrowFired(spawn_position: Vector2, direction: Vector2)
|
||||
|
||||
@export var direction_component: FacingDirectionComponent
|
||||
@export var arrow_spawn_marker: Marker2D
|
||||
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
return PlayerStateMachine.States.FIRING_ARROW
|
||||
|
||||
|
||||
func Enter(_extra_parameters: Dictionary) -> void:
|
||||
PlayerBeganFiringArrow.emit()
|
||||
|
||||
var position := arrow_spawn_marker.global_position
|
||||
var direction := Vector2.ZERO
|
||||
if direction_component.current_direction == Enums.Directions.LEFT:
|
||||
direction = Vector2.LEFT
|
||||
elif direction_component.current_direction == Enums.Directions.RIGHT:
|
||||
direction = Vector2.RIGHT
|
||||
elif direction_component.current_direction == Enums.Directions.UP:
|
||||
direction = Vector2.UP
|
||||
elif direction_component.current_direction == Enums.Directions.DOWN:
|
||||
direction = Vector2.DOWN
|
||||
ArrowFired.emit(position, direction)
|
||||
|
||||
|
||||
func OnFiringArrowAnimationFinished() -> void:
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.IDLE)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cd2ewadcm8oi5
|
||||
47
Entities/Characters/Player/Scripts/States/idle_state.gd
Normal file
47
Entities/Characters/Player/Scripts/States/idle_state.gd
Normal file
@@ -0,0 +1,47 @@
|
||||
extends BaseState
|
||||
class_name PlayerIdleState
|
||||
|
||||
@export var movement_component: MovementComponent
|
||||
|
||||
signal PlayerBecameIdle
|
||||
|
||||
var _sit_queued := false
|
||||
var _sit_queue_pos: Vector2
|
||||
var _sit_queue_dir: Enums.Directions
|
||||
|
||||
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
return PlayerStateMachine.States.IDLE
|
||||
|
||||
|
||||
func Enter(_extra_parameters: Dictionary) -> void:
|
||||
PlayerBecameIdle.emit()
|
||||
|
||||
|
||||
func Update(_delta: float) -> void:
|
||||
var item_a := Input.is_action_just_pressed("use_item_a")
|
||||
|
||||
if item_a:
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.USING_ITEM_A, {})
|
||||
return
|
||||
|
||||
if _sit_queued:
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.SITTING, {"pos": _sit_queue_pos, "dir": _sit_queue_dir})
|
||||
_sit_queued = false
|
||||
return
|
||||
|
||||
if movement_component.movement_vector != Vector2.ZERO:
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.WALKING)
|
||||
|
||||
|
||||
func OnSitOnFurnitureTriggered(sitting_position: Vector2, sitting_direction: Enums.Directions) -> void:
|
||||
if state_machine.GetCurrentStateEnum() != GetStateEnum():
|
||||
return
|
||||
|
||||
_sit_queued = true
|
||||
_sit_queue_pos = sitting_position
|
||||
_sit_queue_dir = sitting_direction
|
||||
|
||||
|
||||
func OnCutsceneStarted() -> void:
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.CUTSCENE)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dkmc1t43gomdb
|
||||
@@ -0,0 +1,30 @@
|
||||
extends BaseState
|
||||
class_name PlayerPlayAnimationState
|
||||
|
||||
signal PlayAnimation(animation_name: String)
|
||||
signal AnimationFinished(animation_name: String)
|
||||
|
||||
var current_animation_name: String
|
||||
|
||||
# Public Methods
|
||||
func GetAnimationBaseName() -> String:
|
||||
return "idle"
|
||||
|
||||
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
return PlayerStateMachine.States.PLAY_ANIMATION
|
||||
|
||||
|
||||
func Enter(_extra_parameters: Dictionary) -> void:
|
||||
current_animation_name = _extra_parameters["animation_name"]
|
||||
print("Playing Player Animation State: [%s]" % current_animation_name)
|
||||
PlayAnimation.emit(current_animation_name)
|
||||
|
||||
|
||||
func Exit() -> void:
|
||||
current_animation_name = ''
|
||||
|
||||
|
||||
func OnAnimationFinished(animation_name: String) -> void:
|
||||
if animation_name != current_animation_name: return
|
||||
AnimationFinished.emit(animation_name)
|
||||
@@ -0,0 +1 @@
|
||||
uid://wfdtd3xlgrvm
|
||||
25
Entities/Characters/Player/Scripts/States/sitting_state.gd
Normal file
25
Entities/Characters/Player/Scripts/States/sitting_state.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends BaseState
|
||||
|
||||
@onready var player: PlayerCharacter = $"../../.."
|
||||
@onready var facing_direction_component: FacingDirectionComponent = $"../../../Components/FacingDirectionComponent"
|
||||
|
||||
func GetAnimationBaseName() -> String:
|
||||
return "idle"
|
||||
|
||||
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
return PlayerStateMachine.States.SITTING
|
||||
|
||||
|
||||
func Enter(extra_parameters: Dictionary) -> void:
|
||||
var pos := extra_parameters["pos"] as Vector2
|
||||
var dir := extra_parameters["dir"] as Enums.Directions
|
||||
|
||||
player.position = pos
|
||||
facing_direction_component.SetDirectionManually(dir)
|
||||
|
||||
|
||||
func Update(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed("player_interact"):
|
||||
player.position = Vector2(player.position.x, player.position.y + 16)
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.IDLE)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bx1a35al4yiej
|
||||
@@ -0,0 +1,15 @@
|
||||
extends BaseState
|
||||
|
||||
@export var body: CharacterBody2D
|
||||
@export var direction_component: FacingDirectionComponent
|
||||
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
return PlayerStateMachine.States.USING_ITEM_A
|
||||
|
||||
|
||||
func GetAnimationBaseName() -> String:
|
||||
return "idle"
|
||||
|
||||
|
||||
func Update(_delta: float) -> void:
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.DRAWING_BOW, { "action_name": "use_item_a" })
|
||||
@@ -0,0 +1 @@
|
||||
uid://ckn7gmtc23b8l
|
||||
27
Entities/Characters/Player/Scripts/States/walking_state.gd
Normal file
27
Entities/Characters/Player/Scripts/States/walking_state.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
extends BaseState
|
||||
|
||||
signal StartedWalking
|
||||
|
||||
@export var walking_speed := 100
|
||||
@export var movement_component: MovementComponent
|
||||
@export var direction_component: FacingDirectionComponent
|
||||
@export var body: CharacterBody2D
|
||||
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
return PlayerStateMachine.States.WALKING
|
||||
|
||||
|
||||
func Enter(_extra_parameters: Dictionary) -> void:
|
||||
StartedWalking.emit()
|
||||
|
||||
|
||||
func Update(_delta: float) -> void:
|
||||
if movement_component.movement_vector == Vector2.ZERO:
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.IDLE)
|
||||
return
|
||||
|
||||
var movement_vector := movement_component.movement_vector
|
||||
body.velocity = movement_vector * walking_speed
|
||||
body.move_and_slide()
|
||||
|
||||
direction_component.ChangeDirectionUsingMovementVector(movement_vector)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bwmmah30t3m0u
|
||||
Reference in New Issue
Block a user