Reworked idle, lookaround and death to the states
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_DEATH = "death"
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_death, player.global_position)
|
||||
player.sprite.animation_finished.connect(_on_aniimation_finished, CONNECT_ONE_SHOT)
|
||||
player.process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
player.sprite.play(ANIMATION_DEATH)
|
||||
get_tree().paused = true
|
||||
|
||||
|
||||
func _on_aniimation_finished() -> void:
|
||||
player.dead.emit()
|
||||
player.queue_free()
|
||||
@@ -0,0 +1 @@
|
||||
uid://d2uiegcx4jeuk
|
||||
@@ -1 +1,23 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const ANIMATION_IDLE = "idle"
|
||||
|
||||
const LOOK_AROUND_CHANCE = 25
|
||||
|
||||
|
||||
@export var look_around_state: PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.animation_looped.connect(_on_animation_looped)
|
||||
player.sprite.play(ANIMATION_IDLE)
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
player.sprite.animation_looped.disconnect(_on_animation_looped)
|
||||
|
||||
|
||||
func _on_animation_looped() -> void:
|
||||
if randi_range(1, 100) <= LOOK_AROUND_CHANCE:
|
||||
switch_state.emit(look_around_state)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
extends PlayerState
|
||||
@@ -0,0 +1 @@
|
||||
uid://cxa3hf7tqpeoa
|
||||
@@ -0,0 +1,21 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
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())
|
||||
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
switch_state.emit(idle_state)
|
||||
|
||||
|
||||
func _get_animation() -> String:
|
||||
return ANIMATION_LOOK_AROUND_1 if randi_range(1, 2) == 1 else ANIMATION_LOOK_AROUND_2
|
||||
@@ -0,0 +1 @@
|
||||
uid://cbv84l1duwfep
|
||||
@@ -0,0 +1,18 @@
|
||||
class_name PlayerStateMachine
|
||||
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 @@
|
||||
uid://dk3t8s0lt2r8n
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://bdk23k2bypj8w"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://3ll3i1fgktg2" path="res://game/state_machine/state_machine.tscn" id="1_7tog0"]
|
||||
[ext_resource type="Script" uid="uid://dk3t8s0lt2r8n" path="res://game/characters/player/state_machine/player_state_machine.gd" id="2_ydgfo"]
|
||||
|
||||
[node name="PlayerStateMachine" unique_id=633169960 instance=ExtResource("1_7tog0")]
|
||||
script = ExtResource("2_ydgfo")
|
||||
@@ -0,0 +1 @@
|
||||
extends PlayerState
|
||||
@@ -0,0 +1 @@
|
||||
uid://nc62375vpnsw
|
||||
Reference in New Issue
Block a user