Added other player states

This commit is contained in:
2026-02-02 22:04:54 +03:00
parent 81d81ae103
commit 63710b691b
26 changed files with 396 additions and 151 deletions
+10 -79
View File
@@ -5,19 +5,6 @@ extends CharacterBody2D
signal dead
const ANIMATION_IDLE = "idle"
const ANIMATION_LOOK_AROUND_1 = "look_around_1"
const ANIMATION_LOOK_AROUND_2 = "look_around_2"
const ANIMATION_WALK_LEFT = "walk_left"
const ANIMATION_WALK_RIGHT = "walk_right"
const ANIMATION_FALL_DOWN = "fall_down"
const ANIMATION_FALL_DOWN_LEFT = "fall_down_left"
const ANIMATION_FALL_DOWN_RIGHT = "fall_down_right"
const ANIMATION_FALL_UP = "fall_up"
const ANIMATION_FALL_UP_LEFT = "fall_up_left"
const ANIMATION_FALL_UP_RIGHT = "fall_up_right"
const ANIMATION_DEATH = "death"
const LOOK_AROUND_CHANCE = 25
const PICKUP_OFFSET = 16.0
@@ -31,7 +18,7 @@ const PICKUP_OFFSET = 16.0
@export_range(0.0, 1.0) var passive_jump_factor := 0.5
var _is_alive := true
var is_dead := false
var _is_switching_needed := false
@@ -42,8 +29,6 @@ var _is_switching_needed := false
@onready var coyote_time_timer : Timer = $CoyoteTimeTimer
@onready var center_area : Area2D = $CenterArea2D
@onready var state_machine : PlayerStateMachine = $PlayerStateMachine
func _ready() -> void:
collision_switcher.material = sprite.material
@@ -64,7 +49,7 @@ func _physics_process(delta: float) -> void:
velocity += get_gravity() * gravity_factor * delta
velocity.y = clampf(velocity.y, -max_fall_speed, max_fall_speed)
if not _is_alive:
if is_dead:
_slow_down(delta)
else:
if Input.is_action_just_pressed("jump"):
@@ -74,14 +59,13 @@ func _physics_process(delta: float) -> void:
SoundManager.play_sfx_stream(SoundManager.sfx_stream_jump, global_position)
velocity.y = -jump_velocity
jump_buffer_timer.stop()
coyote_time_timer.stop()
var direction := Input.get_axis("move_left", "move_right")
if direction:
velocity.x = move_toward(velocity.x, direction * max_speed, acceleration * delta)
else:
_slow_down(delta)
_update_animation()
if _is_switching_needed:
_switch()
@@ -97,7 +81,7 @@ func _input(event: InputEvent) -> void:
func _switch() -> void:
_is_switching_needed = false
if not _is_alive:
if is_dead:
return
if center_area.get_overlapping_bodies().size() == 0:
@@ -108,8 +92,12 @@ func _switch() -> void:
func kill() -> void:
_is_alive = false
state_machine.kill_player()
is_dead = true
func process_dead() -> void:
dead.emit()
queue_free()
func add_pickup(pickup: AbstractPickup) -> void:
@@ -135,41 +123,6 @@ func _is_killing_collider(collider: Object) -> bool:
return node.has_node("PlayerKiller")
func _update_animation() -> void:
var animation := _get_animation()
if sprite.animation != animation and acceleration not in [ANIMATION_IDLE, ANIMATION_LOOK_AROUND_1, ANIMATION_LOOK_AROUND_2]:
sprite.play(animation)
func _get_animation() -> String:
if is_on_floor():
if velocity.x > 0:
return ANIMATION_WALK_RIGHT
elif velocity.x < 0:
return ANIMATION_WALK_LEFT
else:
if is_zero_approx(velocity.x):
if velocity.y > 0:
return ANIMATION_FALL_DOWN
else:
return ANIMATION_FALL_UP
if velocity.x > 0:
if velocity.y > 0:
return ANIMATION_FALL_DOWN_RIGHT
else:
return ANIMATION_FALL_UP_RIGHT
elif velocity.x < 0:
if velocity.y > 0:
return ANIMATION_FALL_DOWN_LEFT
else:
return ANIMATION_FALL_UP_LEFT
if sprite.animation in [ANIMATION_LOOK_AROUND_1, ANIMATION_LOOK_AROUND_2]:
return sprite.animation
return ANIMATION_IDLE
func _rearrange_pickups() -> void:
var children := pickups.get_children()
var pickup_shift := (children.size() - 1) * PICKUP_OFFSET / 2.0
@@ -179,25 +132,3 @@ func _rearrange_pickups() -> void:
var node := children[i] as Node2D
node.position.x = i * PICKUP_OFFSET - pickup_shift
node.position.y = 0
func _play_look_around_animation() -> void:
pass
#sprite.play(ANIMATION_LOOK_AROUND_1 if randi_range(1, 2) == 1 else ANIMATION_LOOK_AROUND_2)
func _on_animation_finished() -> void:
match sprite.animation:
#ANIMATION_LOOK_AROUND_1, ANIMATION_LOOK_AROUND_2:
#sprite.play(ANIMATION_IDLE)
ANIMATION_DEATH:
dead.emit()
queue_free()
func _on_animation_looped() -> void:
pass
#match sprite.animation:
#ANIMATION_IDLE:
#if randi_range(1, 100) <= LOOK_AROUND_CHANCE:
#_play_look_around_animation()
+140 -15
View File
@@ -6,10 +6,16 @@
[ext_resource type="PackedScene" uid="uid://bdk23k2bypj8w" path="res://game/characters/player/state_machine/player_state_machine.tscn" id="4_ybe51"]
[ext_resource type="PackedScene" uid="uid://c0d4wfdg7xjti" path="res://game/characters/player/state_machine/player_state.tscn" id="5_65114"]
[ext_resource type="Script" uid="uid://bnxccvt265hlu" path="res://game/characters/player/state_machine/idle_state.gd" id="6_3qf5w"]
[ext_resource type="Script" uid="uid://nc62375vpnsw" path="res://game/characters/player/state_machine/walk_state.gd" id="7_btbyc"]
[ext_resource type="Script" uid="uid://nc62375vpnsw" path="res://game/characters/player/state_machine/walk_left_state.gd" id="7_btbyc"]
[ext_resource type="Script" uid="uid://cbv84l1duwfep" path="res://game/characters/player/state_machine/look_around_state.gd" id="7_ybe51"]
[ext_resource type="Script" uid="uid://cxa3hf7tqpeoa" path="res://game/characters/player/state_machine/jump_state.gd" id="8_ebhjm"]
[ext_resource type="Script" uid="uid://d2uiegcx4jeuk" path="res://game/characters/player/state_machine/dead_state.gd" id="9_gdxv1"]
[ext_resource type="Script" uid="uid://kufq6bwnv80t" path="res://game/characters/player/state_machine/walk_right_state.gd" id="9_wdx7h"]
[ext_resource type="Script" uid="uid://c0bbmif5ucw28" path="res://game/characters/player/state_machine/jump_left_state.gd" id="11_q2504"]
[ext_resource type="Script" uid="uid://cr0hkb4wggcys" path="res://game/characters/player/state_machine/jump_right_state.gd" id="12_l8uo5"]
[ext_resource type="Script" uid="uid://c7myrm50fnpfn" path="res://game/characters/player/state_machine/fall_state.gd" id="13_m2bqk"]
[ext_resource type="Script" uid="uid://cmimnl6jf78ao" path="res://game/characters/player/state_machine/fall_left_state.gd" id="14_2lnxg"]
[ext_resource type="Script" uid="uid://5s7ko6pcqagy" path="res://game/characters/player/state_machine/fall_right_state.gd" id="15_bfpdl"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"]
radius = 4.0
@@ -24,7 +30,7 @@ collision_mask = 33
script = ExtResource("1_xln5q")
[node name="AnimatedSprite2D" parent="." unique_id=237719081 instance=ExtResource("2_n6ad3")]
animation = &"death"
animation = &"jump_right"
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1101386361]
position = Vector2(0, 1)
@@ -55,32 +61,151 @@ collision_mask = 35
[node name="CollisionShape2D" type="CollisionShape2D" parent="CenterArea2D" unique_id=1350886064]
shape = SubResource("CapsuleShape2D_t6gq4")
[node name="PlayerStateMachine" parent="." unique_id=633169960 node_paths=PackedStringArray("player", "dead_state", "initial_state") instance=ExtResource("4_ybe51")]
[node name="PlayerStateMachine" parent="." unique_id=633169960 node_paths=PackedStringArray("player", "initial_state") instance=ExtResource("4_ybe51")]
player = NodePath("..")
dead_state = NodePath("DeadState")
initial_state = NodePath("IdleState")
[node name="IdleState" parent="PlayerStateMachine" unique_id=739226464 node_paths=PackedStringArray("look_around_state", "player") instance=ExtResource("5_65114")]
[node name="IdleState" parent="PlayerStateMachine" unique_id=739226464 node_paths=PackedStringArray("look_around_state", "player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("6_3qf5w")
look_around_state = NodePath("../LookAroundState")
player = NodePath("../..")
idle_state = NodePath(".")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath("../WalkRightState")
dead_state = NodePath("../DeadState")
jump_state = NodePath("../JumpState")
jump_left_state = NodePath("../JumpLeftState")
jump_right_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath("../FallRightState")
[node name="LookAroundState" parent="PlayerStateMachine" unique_id=946166563 node_paths=PackedStringArray("idle_state", "player") instance=ExtResource("5_65114")]
script = ExtResource("7_ybe51")
idle_state = NodePath("../IdleState")
player = NodePath("../..")
[node name="WalkState" parent="PlayerStateMachine" unique_id=195513070 node_paths=PackedStringArray("player") instance=ExtResource("5_65114")]
[node name="WalkLeftState" parent="PlayerStateMachine" unique_id=195513070 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("7_btbyc")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_left_state = NodePath(".")
walk_right_state = NodePath("../WalkRightState")
dead_state = NodePath("../DeadState")
jump_state = NodePath("../JumpState")
jump_left_state = NodePath("../JumpLeftState")
jump_right_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath("../FallRightState")
[node name="JumpState" parent="PlayerStateMachine" unique_id=1433721843 node_paths=PackedStringArray("player") instance=ExtResource("5_65114")]
script = ExtResource("8_ebhjm")
[node name="WalkRightState" parent="PlayerStateMachine" unique_id=224236087 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("9_wdx7h")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath(".")
dead_state = NodePath("../DeadState")
jump_state = NodePath("../JumpState")
jump_left_state = NodePath("../JumpLeftState")
jump_right_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath("../FallRightState")
[node name="DeadState" parent="PlayerStateMachine" unique_id=2135733235 node_paths=PackedStringArray("player") instance=ExtResource("5_65114")]
script = ExtResource("9_gdxv1")
player = NodePath("../..")
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]
[connection signal="animation_looped" from="AnimatedSprite2D" to="." method="_on_animation_looped"]
[node name="JumpState" parent="PlayerStateMachine" unique_id=1592631166 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("8_ebhjm")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath("../WalkRightState")
dead_state = NodePath("../DeadState")
jump_state = NodePath(".")
jump_left_state = NodePath("../JumpLeftState")
jump_right_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath("../FallRightState")
[node name="JumpLeftState" parent="PlayerStateMachine" unique_id=609248752 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("11_q2504")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath("../WalkRightState")
dead_state = NodePath("../DeadState")
jump_state = NodePath(".")
jump_left_state = NodePath(".")
jump_right_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath("../FallRightState")
[node name="JumpRightState" parent="PlayerStateMachine" unique_id=1936273065 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("12_l8uo5")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath("../WalkRightState")
dead_state = NodePath("../DeadState")
jump_state = NodePath(".")
jump_left_state = NodePath("../JumpLeftState")
jump_right_state = NodePath(".")
fall_state = NodePath("../FallState")
fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath("../FallRightState")
[node name="FallState" parent="PlayerStateMachine" unique_id=329927506 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("13_m2bqk")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath("../WalkRightState")
dead_state = NodePath("../DeadState")
jump_state = NodePath(".")
jump_left_state = NodePath("../JumpLeftState")
jump_right_state = NodePath("../JumpRightState")
fall_state = NodePath(".")
fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath("../FallRightState")
[node name="FallLeftState" parent="PlayerStateMachine" unique_id=730552947 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("14_2lnxg")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath("../WalkRightState")
dead_state = NodePath("../DeadState")
jump_state = NodePath(".")
jump_left_state = NodePath("../JumpLeftState")
jump_right_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
fall_left_state = NodePath(".")
fall_right_state = NodePath("../FallRightState")
[node name="FallRightState" parent="PlayerStateMachine" unique_id=347081029 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("15_bfpdl")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath("../WalkRightState")
dead_state = NodePath("../DeadState")
jump_state = NodePath(".")
jump_left_state = NodePath("../JumpLeftState")
jump_right_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath(".")
[node name="LookAroundState" parent="PlayerStateMachine" unique_id=946166563 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
script = ExtResource("7_ybe51")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath("../WalkRightState")
dead_state = NodePath("../DeadState")
jump_state = NodePath("../JumpState")
jump_left_state = NodePath("../JumpLeftState")
jump_right_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
fall_left_state = NodePath("../FallLeftState")
fall_right_state = NodePath("../FallRightState")
@@ -0,0 +1,80 @@
[gd_scene format=3 uid="uid://dtcad8tdx78tg"]
[ext_resource type="Script" uid="uid://bb8kc32sggrn2" path="res://game/characters/player/player.gd" id="1_xln5q"]
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="2_j06tb"]
[ext_resource type="PackedScene" uid="uid://cvx6akiplg21s" path="res://game/characters/player/player_sprite.tscn" id="2_n6ad3"]
[ext_resource type="PackedScene" uid="uid://bdk23k2bypj8w" path="res://game/characters/player/state_machine/player_state_machine.tscn" id="4_ybe51"]
[ext_resource type="PackedScene" uid="uid://c0d4wfdg7xjti" path="res://game/characters/player/state_machine/player_state.tscn" id="5_65114"]
[ext_resource type="Script" uid="uid://bnxccvt265hlu" path="res://game/characters/player/state_machine/idle_state.gd" id="6_3qf5w"]
[ext_resource type="Script" uid="uid://nc62375vpnsw" path="res://game/characters/player/state_machine/walk_left_state.gd" id="7_btbyc"]
[ext_resource type="Script" uid="uid://cbv84l1duwfep" path="res://game/characters/player/state_machine/look_around_state.gd" id="7_ybe51"]
[ext_resource type="Script" uid="uid://cxa3hf7tqpeoa" path="res://game/characters/player/state_machine/jump_state.gd" id="8_ebhjm"]
[ext_resource type="Script" uid="uid://d2uiegcx4jeuk" path="res://game/characters/player/state_machine/dead_state.gd" id="9_gdxv1"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"]
radius = 4.0
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_t6gq4"]
radius = 2.0
height = 15.0
[node name="Player" type="CharacterBody2D" unique_id=508706417]
collision_layer = 128
collision_mask = 33
script = ExtResource("1_xln5q")
[node name="AnimatedSprite2D" parent="." unique_id=237719081 instance=ExtResource("2_n6ad3")]
animation = &"death"
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1101386361]
position = Vector2(0, 1)
shape = SubResource("CapsuleShape2D_xln5q")
[node name="CollisionSwitcher" parent="." unique_id=601548821 node_paths=PackedStringArray("object") instance=ExtResource("2_j06tb")]
object = NodePath("..")
[node name="Camera2D" type="Camera2D" parent="." unique_id=45512317]
process_callback = 0
position_smoothing_enabled = true
[node name="Pickups" type="Node2D" parent="." unique_id=958829860]
position = Vector2(0, -24)
[node name="JumpBufferTimer" type="Timer" parent="." unique_id=740877224]
wait_time = 0.1
one_shot = true
[node name="CoyoteTimeTimer" type="Timer" parent="." unique_id=117837002]
wait_time = 0.1
one_shot = true
[node name="CenterArea2D" type="Area2D" parent="." unique_id=490866430]
collision_layer = 0
collision_mask = 35
[node name="CollisionShape2D" type="CollisionShape2D" parent="CenterArea2D" unique_id=1350886064]
shape = SubResource("CapsuleShape2D_t6gq4")
[node name="PlayerStateMachine" parent="." unique_id=633169960 node_paths=PackedStringArray("player", "dead_state", "initial_state") instance=ExtResource("4_ybe51")]
player = NodePath("..")
dead_state = NodePath("DeadState")
initial_state = NodePath("IdleState")
[node name="IdleState" parent="PlayerStateMachine" unique_id=739226464 node_paths=PackedStringArray("look_around_state", "player", "idle_state", "walk_state", "jump_state") instance=ExtResource("5_65114")]
script = ExtResource("6_3qf5w")
look_around_state = NodePath("../LookAroundState")
player = NodePath("../..")
idle_state = NodePath(".")
walk_state = NodePath("../WalkLeftState")
jump_state = NodePath("../JumpState")
[node name="LookAroundState" parent="PlayerStateMachine" unique_id=946166563 node_paths=PackedStringArray("player", "idle_state", "walk_state", "jump_state") instance=ExtResource("5_65114")]
script = ExtResource("7_ybe51")
player = NodePath("../..")
idle_state = NodePath("../IdleState")
walk_state = NodePath("../WalkLeftState")
jump_state = NodePath("../JumpState")
[node name="WalkLeftState" parent="PlayerStateMachine" unique_id=195513070 instance=ExtResource("5_65114")]
script = ExtResource("7_btbyc")
player = Object(CharacterBody2D,"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"proce
+42 -42
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=53 format=3 uid="uid://cvx6akiplg21s"]
[gd_scene format=3 uid="uid://cvx6akiplg21s"]
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="1_57ht8"]
[ext_resource type="Texture2D" uid="uid://bjccaucrio6ht" path="res://images/characters/player.png" id="2_mi53p"]
@@ -81,18 +81,6 @@ region = Rect2(64, 96, 32, 32)
atlas = ExtResource("2_mi53p")
region = Rect2(0, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_htqrf"]
atlas = ExtResource("2_mi53p")
region = Rect2(160, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_vkuli"]
atlas = ExtResource("2_mi53p")
region = Rect2(96, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_457no"]
atlas = ExtResource("2_mi53p")
region = Rect2(32, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_n6ad3"]
atlas = ExtResource("2_mi53p")
region = Rect2(0, 0, 32, 32)
@@ -113,6 +101,18 @@ region = Rect2(32, 0, 32, 32)
atlas = ExtResource("2_mi53p")
region = Rect2(0, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_htqrf"]
atlas = ExtResource("2_mi53p")
region = Rect2(160, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_vkuli"]
atlas = ExtResource("2_mi53p")
region = Rect2(96, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_457no"]
atlas = ExtResource("2_mi53p")
region = Rect2(32, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_mi53p"]
atlas = ExtResource("2_mi53p")
region = Rect2(96, 0, 32, 32)
@@ -259,7 +259,7 @@ animations = [{
"texture": SubResource("AtlasTexture_4u621")
}],
"loop": true,
"name": &"fall_down",
"name": &"fall",
"speed": 5.0
}, {
"frames": [{
@@ -267,7 +267,7 @@ animations = [{
"texture": SubResource("AtlasTexture_tqwgk")
}],
"loop": true,
"name": &"fall_down_left",
"name": &"fall_left",
"speed": 5.0
}, {
"frames": [{
@@ -275,31 +275,7 @@ animations = [{
"texture": SubResource("AtlasTexture_ly4f6")
}],
"loop": true,
"name": &"fall_down_right",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_htqrf")
}],
"loop": true,
"name": &"fall_up",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_vkuli")
}],
"loop": true,
"name": &"fall_up_left",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_457no")
}],
"loop": true,
"name": &"fall_up_right",
"name": &"fall_right",
"speed": 5.0
}, {
"frames": [{
@@ -323,6 +299,30 @@ animations = [{
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_htqrf")
}],
"loop": true,
"name": &"jump",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_vkuli")
}],
"loop": true,
"name": &"jump_left",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_457no")
}],
"loop": true,
"name": &"jump_right",
"speed": 5.0
}, {
"frames": [{
"duration": 3.0,
"texture": SubResource("AtlasTexture_mi53p")
}, {
@@ -426,7 +426,7 @@ animations = [{
"speed": 20.0
}]
[node name="AnimatedSprite2D" type="AnimatedSprite2D"]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" unique_id=259457082]
material = SubResource("ShaderMaterial_i05k5")
sprite_frames = SubResource("SpriteFrames_v8w1g")
animation = &"look_around"
animation = &"fall_right"
@@ -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
+7 -3
View File
@@ -1,6 +1,10 @@
extends AbstractLevel
const ANIMATION_WALK_LEFT = "walk_left"
const ANIMATION_WALK_RIGHT = "walk_right"
const CUTSCENE_CAMERA_TIME = 5
const CUTSCENE_HAZE_TIME = 0.1
@@ -96,7 +100,7 @@ func _do_cutscene_phase_one() -> void:
cutscene_camera.enabled = true
cutscene_camera.make_current()
cutscene_fake_player.show()
cutscene_fake_player.play(Player.ANIMATION_WALK_RIGHT, _cutscene_player_speed_factor)
cutscene_fake_player.play(ANIMATION_WALK_RIGHT, _cutscene_player_speed_factor)
var tween : Tween = create_tween()
tween.set_ease(Tween.EASE_IN_OUT)
tween.set_trans(Tween.TRANS_QUAD)
@@ -104,12 +108,12 @@ func _do_cutscene_phase_one() -> void:
func _do_cutscene_phase_four() -> void:
cutscene_fake_player.play(Player.ANIMATION_WALK_LEFT,_cutscene_player_speed_factor)
cutscene_fake_player.play(ANIMATION_WALK_LEFT,_cutscene_player_speed_factor)
func _do_cutscene_phase_six() -> void:
_cutscene_player_speed_factor = 0.25
cutscene_fake_player.play(Player.ANIMATION_WALK_RIGHT, _cutscene_player_speed_factor)
cutscene_fake_player.play(ANIMATION_WALK_RIGHT, _cutscene_player_speed_factor)
func _do_cutscene_phase_seven() -> void:
+3
View File
@@ -25,6 +25,9 @@ func _physics_process(delta: float) -> void:
func _change_state(new_state: AbstractState) -> void:
if new_state == null: return
if new_state == current_state: return
if current_state:
current_state.exit()
current_state = new_state