Compare commits
4 commits
2a865423dc
...
e161eb1117
| Author | SHA1 | Date | |
|---|---|---|---|
| e161eb1117 | |||
| c6b12507d9 | |||
| c284cb4796 | |||
| 5b41872c0f |
6 changed files with 62 additions and 20 deletions
|
|
@ -30,3 +30,25 @@ func _state_update(_delta: float) -> void:
|
||||||
|
|
||||||
func _state_physics_update(_delta: float) -> void:
|
func _state_physics_update(_delta: float) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func match_state(exclude: Array[StringName] = []) -> StringName:
|
||||||
|
var movement_vector: Vector2 = player.get_movement_vector()
|
||||||
|
|
||||||
|
if movement_vector.length() > player.DEADZONE:
|
||||||
|
if WALKING in exclude: return ""
|
||||||
|
return WALKING
|
||||||
|
elif movement_vector.length() < player.DEADZONE:
|
||||||
|
if IDLE in exclude: return ""
|
||||||
|
return IDLE
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func watch_state(exclude: Array[StringName] = []) -> bool:
|
||||||
|
var next_state: StringName = match_state(exclude)
|
||||||
|
if next_state != "":
|
||||||
|
finished.emit(next_state)
|
||||||
|
return true
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,3 @@ func get_movement_vector() -> Vector2:
|
||||||
var x_mov: float = Input.get_action_strength('move_right') - Input.get_action_strength('move_left')
|
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')
|
var y_mov: float = Input.get_action_strength('move_down') - Input.get_action_strength('move_up')
|
||||||
return Vector2(x_mov, y_mov)
|
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,9 +1,10 @@
|
||||||
[gd_scene load_steps=6 format=3 uid="uid://cqm5besqgsb7x"]
|
[gd_scene load_steps=7 format=3 uid="uid://cqm5besqgsb7x"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://dpsocqnk0e6le" path="res://scenes/player/player.gd" id="1_dovo2"]
|
[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="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://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"]
|
[ext_resource type="Script" uid="uid://cl6snimpmxcvu" path="res://scenes/player/states/player_idle.gd" id="3_p47bc"]
|
||||||
|
[ext_resource type="Script" uid="uid://bg5fu1ildsdnq" path="res://scenes/player/states/player_walking.gd" id="4_p47bc"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_gmlin"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_gmlin"]
|
||||||
radius = 6.0
|
radius = 6.0
|
||||||
|
|
@ -12,15 +13,21 @@ height = 14.0
|
||||||
[node name="Player" type="CharacterBody2D"]
|
[node name="Player" type="CharacterBody2D"]
|
||||||
collision_mask = 2
|
collision_mask = 2
|
||||||
script = ExtResource("1_dovo2")
|
script = ExtResource("1_dovo2")
|
||||||
|
max_speed = 95.0
|
||||||
|
|
||||||
[node name="StateMachine" type="Node" parent="."]
|
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("initial_state")]
|
||||||
script = ExtResource("2_lvxji")
|
script = ExtResource("2_lvxji")
|
||||||
|
initial_state = NodePath("Idle")
|
||||||
metadata/_custom_type_script = "uid://diths5s8vd7lr"
|
metadata/_custom_type_script = "uid://diths5s8vd7lr"
|
||||||
|
|
||||||
[node name="Idle" type="Node" parent="StateMachine"]
|
[node name="Idle" type="Node" parent="StateMachine"]
|
||||||
script = ExtResource("3_p47bc")
|
script = ExtResource("3_p47bc")
|
||||||
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||||
|
|
||||||
|
[node name="Walking" type="Node" parent="StateMachine"]
|
||||||
|
script = ExtResource("4_p47bc")
|
||||||
|
metadata/_custom_type_script = "uid://bebe1y51hwns8"
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
position = Vector2(0, -16)
|
position = Vector2(0, -16)
|
||||||
sprite_frames = ExtResource("2_dovo2")
|
sprite_frames = ExtResource("2_dovo2")
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,14 @@ var next_state: StringName
|
||||||
|
|
||||||
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
||||||
print('entering idle')
|
print('entering idle')
|
||||||
#print('entered')
|
|
||||||
|
player.velocity = Vector2.ZERO
|
||||||
|
player.move_and_slide()
|
||||||
|
|
||||||
|
# TODO: animations
|
||||||
|
|
||||||
|
print('entered')
|
||||||
|
|
||||||
|
|
||||||
func _state_physics_update(_delta: float) -> void:
|
func _state_physics_update(_delta: float) -> void:
|
||||||
next_state = player.match_state([IDLE])
|
if watch_state([IDLE]): return
|
||||||
if next_state != "":
|
|
||||||
print(next_state)
|
|
||||||
#finished.emit(next_state)
|
|
||||||
|
|
|
||||||
22
scenes/player/states/player_walking.gd
Normal file
22
scenes/player/states/player_walking.gd
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
extends PlayerState
|
||||||
|
|
||||||
|
|
||||||
|
var next_state: StringName
|
||||||
|
|
||||||
|
|
||||||
|
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
||||||
|
print("entering walking")
|
||||||
|
player.move_and_slide()
|
||||||
|
|
||||||
|
|
||||||
|
func _state_physics_update(_delta: float) -> void:
|
||||||
|
var movement_vector: Vector2 = player.get_movement_vector()
|
||||||
|
var direction: Vector2 = movement_vector.normalized()
|
||||||
|
player.velocity = direction * player.max_speed
|
||||||
|
|
||||||
|
player.move_and_slide()
|
||||||
|
|
||||||
|
if watch_state([WALKING]): return
|
||||||
|
|
||||||
|
# TODO: animations
|
||||||
|
#player.sprite.play(player.anim_dir)
|
||||||
1
scenes/player/states/player_walking.gd.uid
Normal file
1
scenes/player/states/player_walking.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bg5fu1ildsdnq
|
||||||
Loading…
Add table
Reference in a new issue