Clean up path and names
This commit is contained in:
parent
92ccf7279d
commit
1aff1c2e38
46 changed files with 203 additions and 117 deletions
13
scripts/player/states/player_idle_state.gd
Normal file
13
scripts/player/states/player_idle_state.gd
Normal file
|
@ -0,0 +1,13 @@
|
|||
class_name PlayerIdleState
|
||||
extends PlayerState
|
||||
|
||||
func enter(_msg := {}):
|
||||
player.velocity = Vector2.ZERO
|
||||
player.animation_player.play("idle")
|
||||
|
||||
func update(_delta):
|
||||
if get_input_direction() != Vector2.ZERO:
|
||||
state_machine.transition_to("Walk")
|
||||
|
||||
func get_input_direction():
|
||||
return Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
9
scripts/player/states/player_state.gd
Normal file
9
scripts/player/states/player_state.gd
Normal file
|
@ -0,0 +1,9 @@
|
|||
class_name PlayerState
|
||||
extends State
|
||||
|
||||
var player: Player
|
||||
|
||||
func _ready():
|
||||
await owner.ready
|
||||
player = owner as Player
|
||||
assert(player != null)
|
24
scripts/player/states/player_walk_state.gd
Normal file
24
scripts/player/states/player_walk_state.gd
Normal file
|
@ -0,0 +1,24 @@
|
|||
class_name PlayerWalkState
|
||||
extends PlayerState
|
||||
|
||||
func enter(_msg := {}):
|
||||
player.animation_player.play("walk")
|
||||
|
||||
func physics_update(_delta):
|
||||
var direction = get_input_direction()
|
||||
player.velocity = direction * player.speed
|
||||
|
||||
player.move_and_slide() # This method calculate with delta, we don't need to do it.
|
||||
|
||||
if player.velocity == Vector2.ZERO:
|
||||
state_machine.transition_to("Idle")
|
||||
|
||||
func get_input_direction():
|
||||
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
|
||||
if Input.is_action_pressed("move_left"):
|
||||
player.sprite.flip_h = true
|
||||
elif Input.is_action_pressed("move_right"):
|
||||
player.sprite.flip_h = false
|
||||
|
||||
return direction
|
Loading…
Add table
Add a link
Reference in a new issue