Changes
This commit is contained in:
@@ -3,35 +3,36 @@ 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
|
||||
var _used_item_action: String
|
||||
var _animation_finished := false
|
||||
var _movement_componenent: MovementComponent
|
||||
|
||||
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
|
||||
_animation_finished = false
|
||||
_used_item_action = extra_parameters.action_name
|
||||
_movement_componenent = ComponentUtils.GetMovementComponent(body)
|
||||
PlayerBeganDrawingBow.emit()
|
||||
|
||||
|
||||
func Update(_delta: float) -> void:
|
||||
if !animation_finished:
|
||||
if !_animation_finished:
|
||||
return
|
||||
|
||||
if !Input.is_action_pressed(used_item_action):
|
||||
if !Input.is_action_pressed(_used_item_action):
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.FIRING_ARROW)
|
||||
return
|
||||
|
||||
var movement_vector := movement_componenent.movement_vector
|
||||
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
|
||||
_animation_finished = true
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
extends BaseState
|
||||
class_name PlayerIdleState
|
||||
|
||||
@export var movement_component: MovementComponent
|
||||
|
||||
signal PlayerBecameIdle
|
||||
|
||||
@export var player: PlayerCharacter
|
||||
|
||||
var _movement_component: MovementComponent
|
||||
var _sit_queued := false
|
||||
var _sit_queue_pos: Vector2
|
||||
var _sit_queue_dir: Enums.Directions
|
||||
@@ -15,6 +16,10 @@ func GetStateEnum() -> PlayerStateMachine.States:
|
||||
|
||||
|
||||
func Enter(_extra_parameters: Dictionary) -> void:
|
||||
_movement_component = ComponentUtils.GetMovementComponent(player)
|
||||
if not _movement_component:
|
||||
print_rich("[color=yellow]Warning: Player does not have a movement component...[/color]")
|
||||
|
||||
PlayerBecameIdle.emit()
|
||||
|
||||
|
||||
@@ -30,7 +35,7 @@ func Update(_delta: float) -> void:
|
||||
_sit_queued = false
|
||||
return
|
||||
|
||||
if movement_component.movement_vector != Vector2.ZERO:
|
||||
if _movement_component and _movement_component.movement_vector != Vector2.ZERO:
|
||||
state_machine.QueueStateChange(PlayerStateMachine.States.WALKING)
|
||||
|
||||
|
||||
|
||||
@@ -3,24 +3,27 @@ extends BaseState
|
||||
signal StartedWalking
|
||||
|
||||
@export var walking_speed := 100
|
||||
@export var movement_component: MovementComponent
|
||||
@export var direction_component: FacingDirectionComponent
|
||||
@export var body: CharacterBody2D
|
||||
|
||||
var _movement_component: MovementComponent
|
||||
|
||||
func GetStateEnum() -> PlayerStateMachine.States:
|
||||
return PlayerStateMachine.States.WALKING
|
||||
|
||||
|
||||
func Enter(_extra_parameters: Dictionary) -> void:
|
||||
_movement_component = ComponentUtils.GetMovementComponent(body)
|
||||
StartedWalking.emit()
|
||||
|
||||
|
||||
func Update(_delta: float) -> void:
|
||||
if movement_component.movement_vector == Vector2.ZERO:
|
||||
var movement_vector := _movement_component.movement_vector
|
||||
|
||||
if 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()
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@ class_name MovementComponent
|
||||
|
||||
signal MovementInput(movement_vector: Vector2)
|
||||
|
||||
# Dynamic Exports
|
||||
@export var body: CharacterBody2D
|
||||
|
||||
var movement_vector: Vector2
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
[ext_resource type="PackedScene" uid="uid://c2ydbmmvnfca6" path="res://Entities/Characters/Player/state_machine.tscn" id="1_lyjr2"]
|
||||
[ext_resource type="Script" uid="uid://dacvayqstkvws" path="res://Entities/Characters/Player/Scripts/player.gd" id="1_qqvsf"]
|
||||
[ext_resource type="Script" uid="uid://b0l02v61if6k8" path="res://Scripts/Components/facing_direction_component.gd" id="1_siygm"]
|
||||
[ext_resource type="Script" uid="uid://dwclkwbig1uii" path="res://Entities/Characters/Player/Scripts/movement_component.gd" id="4_apx8m"]
|
||||
[ext_resource type="Script" uid="uid://dkmc1t43gomdb" path="res://Entities/Characters/Player/Scripts/States/idle_state.gd" id="4_dxcao"]
|
||||
[ext_resource type="Script" uid="uid://ckn7gmtc23b8l" path="res://Entities/Characters/Player/Scripts/States/using_item_a_state.gd" id="5_1mdwi"]
|
||||
[ext_resource type="Script" uid="uid://bwmmah30t3m0u" path="res://Entities/Characters/Player/Scripts/States/walking_state.gd" id="5_cscr0"]
|
||||
@@ -40,24 +39,19 @@ shape = SubResource("RectangleShape2D_apx8m")
|
||||
[node name="FacingDirectionComponent" type="Node" parent="Components" unique_id=408127032]
|
||||
script = ExtResource("1_siygm")
|
||||
|
||||
[node name="MovementComponent" type="Node" parent="Components" unique_id=1773880772 node_paths=PackedStringArray("body")]
|
||||
script = ExtResource("4_apx8m")
|
||||
body = NodePath("../..")
|
||||
|
||||
[node name="State Machine" parent="." unique_id=732559774 node_paths=PackedStringArray("states_container", "current_state") instance=ExtResource("1_lyjr2")]
|
||||
states_container = NodePath("States")
|
||||
current_state = NodePath("States/Idle State")
|
||||
|
||||
[node name="States" type="Node" parent="State Machine" unique_id=1171587216]
|
||||
|
||||
[node name="Idle State" type="Node" parent="State Machine/States" unique_id=2017409248 node_paths=PackedStringArray("movement_component", "state_machine")]
|
||||
[node name="Idle State" type="Node" parent="State Machine/States" unique_id=2017409248 node_paths=PackedStringArray("player", "state_machine")]
|
||||
script = ExtResource("4_dxcao")
|
||||
movement_component = NodePath("../../../Components/MovementComponent")
|
||||
player = NodePath("../../..")
|
||||
state_machine = NodePath("../..")
|
||||
|
||||
[node name="Walking State" type="Node" parent="State Machine/States" unique_id=1661048365 node_paths=PackedStringArray("movement_component", "direction_component", "body", "state_machine")]
|
||||
[node name="Walking State" type="Node" parent="State Machine/States" unique_id=1661048365 node_paths=PackedStringArray("direction_component", "body", "state_machine")]
|
||||
script = ExtResource("5_cscr0")
|
||||
movement_component = NodePath("../../../Components/MovementComponent")
|
||||
direction_component = NodePath("../../../Components/FacingDirectionComponent")
|
||||
body = NodePath("../../..")
|
||||
state_machine = NodePath("../..")
|
||||
@@ -68,9 +62,8 @@ body = NodePath("../../..")
|
||||
direction_component = NodePath("../../../Components/FacingDirectionComponent")
|
||||
state_machine = NodePath("../..")
|
||||
|
||||
[node name="Drawing Bow State" type="Node" parent="State Machine/States" unique_id=317681716 node_paths=PackedStringArray("movement_componenent", "body", "state_machine")]
|
||||
[node name="Drawing Bow State" type="Node" parent="State Machine/States" unique_id=317681716 node_paths=PackedStringArray("body", "state_machine")]
|
||||
script = ExtResource("7_cscr0")
|
||||
movement_componenent = NodePath("../../../Components/MovementComponent")
|
||||
body = NodePath("../../..")
|
||||
state_machine = NodePath("../..")
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://nbkisxm2oekn"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dwclkwbig1uii" path="res://Entities/Characters/Player/Scripts/movement_component.gd" id="1_b2nib"]
|
||||
|
||||
[node name="Movement Component" type="Node" unique_id=737644583]
|
||||
script = ExtResource("1_b2nib")
|
||||
Reference in New Issue
Block a user