Added base player sprite
This commit is contained in:
@@ -1 +1,28 @@
|
||||
extends AbstractPlayerState
|
||||
|
||||
|
||||
@export var running_left : AbstractPlayerState
|
||||
@export var running_right : AbstractPlayerState
|
||||
@export var jump_left : AbstractPlayerState
|
||||
@export var jump_right : AbstractPlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.player_sprite.play(ANIMATION_IDLE)
|
||||
|
||||
|
||||
func physics_process(_delta: float) -> void:
|
||||
if player.is_on_floor():
|
||||
if is_zero_approx(player.velocity.x):
|
||||
pass
|
||||
elif player.velocity.x < 0.0:
|
||||
switch_state.emit(running_left)
|
||||
elif player.velocity.x > 0.0:
|
||||
switch_state.emit(running_right)
|
||||
else:
|
||||
if is_zero_approx(player.velocity.x):
|
||||
switch_state.emit([jump_left, jump_right].pick_random())
|
||||
elif player.velocity.x < 0.0:
|
||||
switch_state.emit(jump_left)
|
||||
elif player.velocity.x > 0.0:
|
||||
switch_state.emit(jump_right)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
extends AbstractPlayerState
|
||||
|
||||
|
||||
enum Direction {
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
|
||||
@export var direction := Direction.Left
|
||||
|
||||
@export var idle : AbstractPlayerState
|
||||
@export var another_direction : AbstractPlayerState
|
||||
@export var run : AbstractPlayerState
|
||||
@export var run_another_direction : AbstractPlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.blade_sprite.show()
|
||||
match direction:
|
||||
Direction.Left:
|
||||
player.player_sprite.play(ANIMATION_JUMP_LEFT)
|
||||
player.blade_sprite.play(ANIMATION_JUMP_LEFT)
|
||||
Direction.Right:
|
||||
player.player_sprite.play(ANIMATION_JUMP_RIGHT)
|
||||
player.blade_sprite.play(ANIMATION_JUMP_RIGHT)
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
player.blade_sprite.hide()
|
||||
|
||||
|
||||
func physics_process(_delta: float) -> void:
|
||||
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(run)
|
||||
else:
|
||||
switch_state.emit(run_another_direction)
|
||||
Direction.Right:
|
||||
if player.velocity.x > 0.0:
|
||||
switch_state.emit(run)
|
||||
else:
|
||||
switch_state.emit(run_another_direction)
|
||||
else:
|
||||
if not is_zero_approx(player.velocity.x):
|
||||
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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ddrglfm23s65k
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_scene format=3 uid="uid://bboaskqiwnbsb"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dqkewlpol05ap" path="res://game/entities/player/abstract_player_state.tscn" id="1_8pnwa"]
|
||||
[ext_resource type="Script" uid="uid://ddrglfm23s65k" path="res://game/entities/player/states/jump_state.gd" id="2_y8wem"]
|
||||
|
||||
[node name="JumpState" unique_id=836520368 instance=ExtResource("1_8pnwa")]
|
||||
script = ExtResource("2_y8wem")
|
||||
direction = 0
|
||||
@@ -0,0 +1,59 @@
|
||||
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:
|
||||
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, jump_another_direction].pick_random())
|
||||
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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ddait0epupp37
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_scene format=3 uid="uid://35g5buv0k1s6"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dqkewlpol05ap" path="res://game/entities/player/abstract_player_state.tscn" id="1_vmphp"]
|
||||
[ext_resource type="Script" uid="uid://ddait0epupp37" path="res://game/entities/player/states/running_state.gd" id="2_va6ao"]
|
||||
|
||||
[node name="RunningState" unique_id=836520368 instance=ExtResource("1_vmphp")]
|
||||
script = ExtResource("2_va6ao")
|
||||
direction = 0
|
||||
Reference in New Issue
Block a user