2023-06-11 23:38:54 +02:00
|
|
|
class_name PlayerWalkState
|
|
|
|
extends PlayerState
|
|
|
|
|
|
|
|
func enter(_msg := {}):
|
|
|
|
player.animation_player.play("walk")
|
|
|
|
|
2023-06-18 20:30:25 +02:00
|
|
|
func physics_update(delta):
|
2023-06-11 23:38:54 +02:00
|
|
|
var direction = get_input_direction()
|
2023-06-18 20:30:25 +02:00
|
|
|
var velocity = direction * player.speed
|
|
|
|
|
|
|
|
var collision = player.move_and_collide(velocity * delta)
|
|
|
|
if collision and Input.is_action_pressed("hit"):
|
|
|
|
state_machine.transition_to("Throw")
|
2023-06-11 23:38:54 +02:00
|
|
|
|
2023-06-18 20:30:25 +02:00
|
|
|
if velocity == Vector2.ZERO:
|
2023-06-11 23:38:54 +02:00
|
|
|
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
|