Added wall states
This commit is contained in:
@@ -13,6 +13,7 @@ enum Direction {
|
||||
@export var another_direction : AbstractPlayerState
|
||||
@export var run : AbstractPlayerState
|
||||
@export var run_another_direction : AbstractPlayerState
|
||||
@export var wall : AbstractPlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
@@ -47,6 +48,8 @@ func physics_process(_delta: float) -> void:
|
||||
switch_state.emit(run)
|
||||
else:
|
||||
switch_state.emit(run_another_direction)
|
||||
elif player.is_on_wall():
|
||||
switch_state.emit(wall)
|
||||
else:
|
||||
if not is_zero_approx(player.velocity.x):
|
||||
match direction:
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
extends AbstractPlayerState
|
||||
|
||||
|
||||
const PARTICLE_FACTOR = 100.0
|
||||
|
||||
|
||||
enum Direction {
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
|
||||
@export var direction := Direction.Left
|
||||
|
||||
@export var idle : AbstractPlayerState
|
||||
@export var jump : AbstractPlayerState
|
||||
|
||||
@export var particles : GPUParticles2D
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
particles.emitting = true
|
||||
match direction:
|
||||
Direction.Left:
|
||||
player.player_sprite.play(ANIMATION_WALL_LEFT)
|
||||
Direction.Right:
|
||||
player.player_sprite.play(ANIMATION_WALL_RIGHT)
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
particles.emitting = false
|
||||
|
||||
|
||||
func physics_process(_delta: float) -> void:
|
||||
particles.amount_ratio = clampf(player.velocity.y / PARTICLE_FACTOR, 0.0, 1.0)
|
||||
|
||||
if player.is_on_floor():
|
||||
switch_state.emit(idle)
|
||||
elif not player.is_on_wall():
|
||||
switch_state.emit(jump)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bghqpnc7vmmlh
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://ba5sknbijujl2"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dqkewlpol05ap" path="res://game/entities/player/abstract_player_state.tscn" id="1_vvc6s"]
|
||||
[ext_resource type="Script" uid="uid://bghqpnc7vmmlh" path="res://game/entities/player/states/wall_state.gd" id="2_kmlwa"]
|
||||
|
||||
[node name="WallState" unique_id=836520368 instance=ExtResource("1_vvc6s")]
|
||||
script = ExtResource("2_kmlwa")
|
||||
Reference in New Issue
Block a user