Files
NeonCollapse/game/entities/player/states/running_state.gd
T
2026-07-02 21:34:10 +03:00

61 lines
1.5 KiB
GDScript

extends AbstractPlayerState
enum Direction {
Left,
Right,
}
@export var direction := Direction.Left
@export var idle : AbstractPlayerState
@export var another_direction : AbstractPlayerState
@export var jump : AbstractPlayerState
@export var jump_another_direction : AbstractPlayerState
func enter() -> void:
player.blade_sprite.show()
match direction:
Direction.Left:
player.player_sprite.play(ANIMATION_RUN_LEFT)
player.blade_sprite.play(ANIMATION_RUN_LEFT)
Direction.Right:
player.player_sprite.play(ANIMATION_RUN_RIGHT)
player.blade_sprite.play(ANIMATION_RUN_RIGHT)
func exit() -> void:
player.blade_sprite.hide()
func physics_process(_delta: float) -> void:
player.player_sprite.speed_scale = max(player.velocity.x / player.move_max_speed_normal, 0.5)
if player.is_on_floor():
if is_zero_approx(player.velocity.x):
switch_state.emit(idle)
else:
match direction:
Direction.Left:
if player.velocity.x > 0.0:
switch_state.emit(another_direction)
Direction.Right:
if player.velocity.x < 0.0:
switch_state.emit(another_direction)
else:
if is_zero_approx(player.velocity.x):
switch_state.emit(jump if direction == Direction.Left else jump_another_direction)
else:
match direction:
Direction.Left:
if player.velocity.x < 0.0:
switch_state.emit(jump)
else:
switch_state.emit(jump_another_direction)
Direction.Right:
if player.velocity.x > 0.0:
switch_state.emit(jump)
else:
switch_state.emit(jump_another_direction)