Compare commits
3 commits
66039b70d9
...
2a865423dc
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a865423dc | |||
| e07315023c | |||
| c1de69a1c0 |
6 changed files with 50 additions and 2 deletions
|
|
@ -12,7 +12,7 @@ func _ready() -> void:
|
|||
assert(player != null, "The PlayerState state type must be used only in the player scene. It needs the owner to be a Player node.")
|
||||
|
||||
|
||||
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
||||
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@
|
|||
signal finished(next_state_path: String, data: Dictionary)
|
||||
|
||||
|
||||
## Universal paused state
|
||||
const PAUSED = "Paused"
|
||||
|
||||
## For 'ghost frame' update fix
|
||||
var is_active: bool = false:
|
||||
set(value):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,28 @@
|
|||
class_name Player extends CharacterBody2D
|
||||
|
||||
|
||||
const DEADZONE = 0.1
|
||||
|
||||
@export var max_speed: float = 300.0
|
||||
|
||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
@onready var state_machine: StateMachine = $StateMachine
|
||||
|
||||
|
||||
func get_movement_vector() -> Vector2:
|
||||
var x_mov: float = Input.get_action_strength('move_right') - Input.get_action_strength('move_left')
|
||||
var y_mov: float = Input.get_action_strength('move_down') - Input.get_action_strength('move_up')
|
||||
return Vector2(x_mov, y_mov)
|
||||
|
||||
|
||||
func match_state(exclude: Array[StringName] = []) -> StringName:
|
||||
var movement_vector: Vector2 = get_movement_vector()
|
||||
|
||||
if movement_vector.length() > DEADZONE:
|
||||
if PlayerState.WALKING in exclude: return ""
|
||||
return PlayerState.WALKING
|
||||
elif movement_vector.length() < DEADZONE:
|
||||
if PlayerState.IDLE in exclude: return ""
|
||||
return PlayerState.IDLE
|
||||
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://cqm5besqgsb7x"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://cqm5besqgsb7x"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dpsocqnk0e6le" path="res://scenes/player/player.gd" id="1_dovo2"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://6v5nyv2wo47g" path="res://scenes/player/assets/yukotsuki.aseprite" id="2_dovo2"]
|
||||
[ext_resource type="Script" uid="uid://diths5s8vd7lr" path="res://classes/state_machine/state_machine.gd" id="2_lvxji"]
|
||||
[ext_resource type="Script" uid="uid://cl6snimpmxcvu" path="res://scenes/player/states/player_idle.gd" id="3_p47bc"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_gmlin"]
|
||||
radius = 6.0
|
||||
|
|
@ -11,6 +13,14 @@ height = 14.0
|
|||
collision_mask = 2
|
||||
script = ExtResource("1_dovo2")
|
||||
|
||||
[node name="StateMachine" type="Node" parent="."]
|
||||
script = ExtResource("2_lvxji")
|
||||
metadata/_custom_type_script = "uid://diths5s8vd7lr"
|
||||
|
||||
[node name="Idle" type="Node" parent="StateMachine"]
|
||||
script = ExtResource("3_p47bc")
|
||||
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
position = Vector2(0, -16)
|
||||
sprite_frames = ExtResource("2_dovo2")
|
||||
|
|
|
|||
16
scenes/player/states/player_idle.gd
Normal file
16
scenes/player/states/player_idle.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
extends PlayerState
|
||||
|
||||
|
||||
var next_state: StringName
|
||||
|
||||
|
||||
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
||||
print('entering idle')
|
||||
#print('entered')
|
||||
|
||||
|
||||
func _state_physics_update(_delta: float) -> void:
|
||||
next_state = player.match_state([IDLE])
|
||||
if next_state != "":
|
||||
print(next_state)
|
||||
#finished.emit(next_state)
|
||||
1
scenes/player/states/player_idle.gd.uid
Normal file
1
scenes/player/states/player_idle.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cl6snimpmxcvu
|
||||
Loading…
Add table
Reference in a new issue