Added other player states
This commit is contained in:
@@ -13,6 +13,9 @@ func enter() -> void:
|
||||
get_tree().paused = true
|
||||
|
||||
|
||||
func physics_process(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_aniimation_finished() -> void:
|
||||
player.dead.emit()
|
||||
player.queue_free()
|
||||
player.process_dead()
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_FALL_LEFT = "fall_left"
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.play(ANIMATION_FALL_LEFT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cmimnl6jf78ao
|
||||
@@ -0,0 +1,8 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_FALL_RIGHT = "fall_right"
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.play(ANIMATION_FALL_RIGHT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://5s7ko6pcqagy
|
||||
@@ -0,0 +1,8 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_FALL = "fall"
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.play(ANIMATION_FALL)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c7myrm50fnpfn
|
||||
@@ -0,0 +1,8 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_JUMP_LEFT = "jump_left"
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.play(ANIMATION_JUMP_LEFT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c0bbmif5ucw28
|
||||
@@ -0,0 +1,8 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_JUMP_RIGHT = "jump_right"
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.play(ANIMATION_JUMP_RIGHT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cr0hkb4wggcys
|
||||
@@ -1 +1,8 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_JUMP = "jump"
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.play(ANIMATION_JUMP)
|
||||
|
||||
@@ -5,9 +5,6 @@ const ANIMATION_LOOK_AROUND_1 = "look_around_1"
|
||||
const ANIMATION_LOOK_AROUND_2 = "look_around_2"
|
||||
|
||||
|
||||
@export var idle_state: PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.animation_finished.connect(_on_animation_finished, CONNECT_ONE_SHOT)
|
||||
player.sprite.play(_get_animation())
|
||||
|
||||
@@ -3,3 +3,43 @@ extends AbstractState
|
||||
|
||||
|
||||
@export var player: Player
|
||||
|
||||
|
||||
@export var idle_state: PlayerState
|
||||
@export var walk_left_state: PlayerState
|
||||
@export var walk_right_state: PlayerState
|
||||
@export var dead_state: PlayerState
|
||||
@export var jump_state: PlayerState
|
||||
@export var jump_left_state: PlayerState
|
||||
@export var jump_right_state: PlayerState
|
||||
@export var fall_state: PlayerState
|
||||
@export var fall_left_state: PlayerState
|
||||
@export var fall_right_state: PlayerState
|
||||
|
||||
|
||||
func physics_process(_delta: float) -> void:
|
||||
if player.is_dead:
|
||||
switch_state.emit(dead_state)
|
||||
elif player.velocity.is_zero_approx():
|
||||
switch_state.emit(idle_state)
|
||||
elif is_zero_approx(player.velocity.y):
|
||||
if player.velocity.x < 0:
|
||||
switch_state.emit(walk_left_state)
|
||||
else:
|
||||
switch_state.emit(walk_right_state)
|
||||
else:
|
||||
if player.velocity.y < 0:
|
||||
if is_zero_approx(player.velocity.x):
|
||||
switch_state.emit(jump_state)
|
||||
elif player.velocity.x < 0:
|
||||
switch_state.emit(jump_left_state)
|
||||
else:
|
||||
switch_state.emit(jump_right_state)
|
||||
else:
|
||||
if is_zero_approx(player.velocity.x):
|
||||
switch_state.emit(fall_state)
|
||||
elif player.velocity.x < 0:
|
||||
switch_state.emit(fall_left_state)
|
||||
else:
|
||||
switch_state.emit(fall_right_state)
|
||||
|
||||
|
||||
@@ -4,15 +4,9 @@ extends StateMachine
|
||||
|
||||
@export var player: Player
|
||||
|
||||
@export var dead_state: PlayerState
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not player.is_node_ready():
|
||||
await player.ready
|
||||
|
||||
super._ready()
|
||||
|
||||
|
||||
func kill_player() -> void:
|
||||
_change_state(dead_state)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_WALK_LEFT = "walk_left"
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.play(ANIMATION_WALK_LEFT)
|
||||
@@ -0,0 +1,8 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_WALK_RIGHT = "walk_right"
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.play(ANIMATION_WALK_RIGHT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://kufq6bwnv80t
|
||||
@@ -1 +0,0 @@
|
||||
extends PlayerState
|
||||
Reference in New Issue
Block a user