2023-06-11 23:38:54 +02:00
|
|
|
class_name PlayerWalkState
|
|
|
|
extends PlayerState
|
|
|
|
|
|
|
|
func enter(_msg := {}):
|
2023-06-28 21:29:55 +02:00
|
|
|
player.play_walk_animation()
|
2023-06-11 23:38:54 +02:00
|
|
|
|
2023-06-18 20:30:25 +02:00
|
|
|
func physics_update(delta):
|
2023-06-28 00:07:13 +02:00
|
|
|
var direction = player.get_input_direction()
|
2023-06-18 20:30:25 +02:00
|
|
|
var velocity = direction * player.speed
|
2023-06-28 00:07:13 +02:00
|
|
|
|
|
|
|
player.flip_sprite()
|
2023-06-28 21:29:55 +02:00
|
|
|
|
2023-06-18 20:30:25 +02:00
|
|
|
var collision = player.move_and_collide(velocity * delta)
|
|
|
|
if collision and Input.is_action_pressed("hit"):
|
2023-06-28 21:29:55 +02:00
|
|
|
state_machine.transition_to("HitBall")
|
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")
|