Added cultist fall states

This commit is contained in:
2026-02-06 01:18:35 +03:00
parent a5a3fa2acf
commit c3522f5417
22 changed files with 141 additions and 195 deletions
+11 -51
View File
@@ -8,11 +8,6 @@ enum Type {
Random,
}
enum Facing {
Front,
Rear,
}
enum State {
Idle,
WalkLeft,
@@ -34,7 +29,6 @@ const DIRECTION_RIGHT = 1
@export var type : Type = Type.Standing
@export var facing : Facing = Facing.Front
@export var initial_state : State = State.Idle
@@ -62,9 +56,6 @@ func _ready() -> void:
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity += get_gravity() * delta
match _state:
State.ChasingLeft:
_process_player_ray(left_player_distant_ray)
@@ -74,6 +65,8 @@ func _physics_process(delta: float) -> void:
else:
_update_x_velocity(DIRECTION_LEFT, MAX_CHASE_SPEED, delta)
_check_wall_collision_and_switch_state(DIRECTION_LEFT)
_update_animation()
move_and_slide()
State.ChasingRight:
_process_player_ray(right_player_distant_ray)
if position.x > _target_x:
@@ -82,24 +75,28 @@ func _physics_process(delta: float) -> void:
else:
_update_x_velocity(DIRECTION_RIGHT, MAX_CHASE_SPEED, delta)
_check_wall_collision_and_switch_state(DIRECTION_RIGHT)
_update_animation()
move_and_slide()
State.WalkLeft:
if _process_player_ray(left_player_distant_ray):
_set_chase_state()
_update_x_velocity(DIRECTION_LEFT, MAX_WALK_SPEED, delta)
_check_wall_collision_and_switch_state(DIRECTION_LEFT)
_update_animation()
move_and_slide()
State.WalkRight:
if _process_player_ray(right_player_distant_ray):
_set_chase_state()
_update_x_velocity(DIRECTION_RIGHT, MAX_WALK_SPEED, delta)
_check_wall_collision_and_switch_state(DIRECTION_RIGHT)
_update_animation()
move_and_slide()
State.LookAround:
_update_x_velocity(0, MAX_WALK_SPEED * 2, delta)
if not _target_found:
var close_rays : Array[RayCast2D] = [left_player_close_ray, right_player_close_ray]
_target_found = _process_player_rays(close_rays)
_update_animation()
move_and_slide()
@@ -191,60 +188,23 @@ func _update_animation() -> void:
_play_idle_animation()
State.LookAround:
_play_look_around_animation()
else:
_play_fall_animation()
func _play_idle_animation() -> void:
match facing:
Facing.Front:
_play_animation(CultistSprite.ANIMATION_IDLE_FRONT)
Facing.Rear:
_play_animation(CultistSprite.ANIMATION_IDLE_REAR)
_play_animation(CultistSprite.ANIMATION_IDLE)
func _play_look_around_animation() -> void:
if _is_current_animation_look_around(): return
match facing:
Facing.Front:
var animation := _get_random_animation(CultistSprite.LOOK_AROUND_FRONT_ANIMATIONS)
_play_animation(animation)
Facing.Rear:
var animation := _get_random_animation(CultistSprite.LOOK_AROUND_REAR_ANIMATIONS)
_play_animation(animation)
func _play_fall_animation() -> void:
if is_zero_approx(velocity.x):
if velocity.y < 0:
_play_animation(CultistSprite.ANIMATION_FALL_UP)
else:
_play_animation(CultistSprite.ANIMATION_FALL_DOWN)
elif velocity.x < 0:
if velocity.y < 0:
_play_animation(CultistSprite.ANIMATION_FALL_UP_LEFT)
else:
_play_animation(CultistSprite.ANIMATION_FALL_DOWN_LEFT)
else:
if velocity.y < 0:
_play_animation(CultistSprite.ANIMATION_FALL_UP_RIGHT)
else:
_play_animation(CultistSprite.ANIMATION_FALL_DOWN_RIGHT)
_play_animation(CultistSprite.LOOK_AROUND_ANIMATIONS.pick_random())
func _is_current_animation_look_around() -> bool:
if not sprite.is_playing(): return false
if sprite.animation in CultistSprite.LOOK_AROUND_FRONT_ANIMATIONS: return true
if sprite.animation in CultistSprite.LOOK_AROUND_REAR_ANIMATIONS: return true
if sprite.animation in CultistSprite.LOOK_AROUND_ANIMATIONS: return true
return false
func _get_random_animation(animations: Array[String]) -> String:
var index := randi_range(0, animations.size() - 1)
return animations[index]
func _play_animation(animation: String) -> void:
if not sprite.is_playing() or sprite.animation != animation:
sprite.play(animation)
@@ -6,6 +6,10 @@
[ext_resource type="PackedScene" uid="uid://bg7k6ovbk1xgm" path="res://game/characters/enemies/state_machine/cultist_state_machine.tscn" id="4_yu28k"]
[ext_resource type="PackedScene" uid="uid://bq1v55jv4c6qe" path="res://game/characters/enemies/state_machine/cultist_state.tscn" id="5_tu2pi"]
[ext_resource type="Script" uid="uid://cdw73paln1rg8" path="res://game/characters/enemies/state_machine/idle_state.gd" id="6_e5j7k"]
[ext_resource type="Script" uid="uid://bqnq6m0s4etqh" path="res://game/characters/enemies/state_machine/fall_state.gd" id="7_7tkj8"]
[ext_resource type="Script" uid="uid://b8o0lvuy6a5q1" path="res://game/characters/enemies/state_machine/fall_left_state.gd" id="8_2opx4"]
[ext_resource type="Script" uid="uid://cxg54u14yb6go" path="res://game/characters/enemies/state_machine/fall_right_state.gd" id="9_lu83c"]
[ext_resource type="Script" uid="uid://bfp8gywqqkju7" path="res://game/characters/enemies/state_machine/look_around_state.gd" id="10_lu83c"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_mocsw"]
radius = 4.0
@@ -88,6 +92,25 @@ initial_state = NodePath("IdleState")
script = ExtResource("6_e5j7k")
cultist = NodePath("../..")
[node name="FallState" parent="CultistStateMachine" unique_id=1764777802 node_paths=PackedStringArray("look_around_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("7_7tkj8")
look_around_state = NodePath("../LookAroundState")
cultist = NodePath("../..")
[node name="FallLeftState" parent="CultistStateMachine" unique_id=1011952297 node_paths=PackedStringArray("look_around_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("8_2opx4")
look_around_state = NodePath("../LookAroundState")
cultist = NodePath("../..")
[node name="FallRightState" parent="CultistStateMachine" unique_id=1932915544 node_paths=PackedStringArray("look_around_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("9_lu83c")
look_around_state = NodePath("../LookAroundState")
cultist = NodePath("../..")
[node name="LookAroundState" parent="CultistStateMachine" unique_id=2025927882 node_paths=PackedStringArray("cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("10_lu83c")
cultist = NodePath("../..")
[connection signal="animation_finished" from="CultistSprite" to="." method="_on_animation_finished"]
[connection signal="animation_looped" from="CultistSprite" to="." method="_on_animation_looped"]
[connection signal="body_entered" from="PlayerTouchArea" to="." method="_on_player_touch_area_entered"]
+13 -19
View File
@@ -2,28 +2,22 @@ class_name CultistSprite
extends AnimatedSprite2D
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_IDLE_FRONT = "idle_front"
const ANIMATION_IDLE_REAR = "idle_rear"
const ANIMATION_LOOK_AROUND_FRONT_1 = "look_around_front_1"
const ANIMATION_LOOK_AROUND_FRONT_2 = "look_around_front_2"
const ANIMATION_LOOK_AROUND_REAR_1 = "look_around_rear_1"
const ANIMATION_LOOK_AROUND_REAR_2 = "look_around_rear_2"
const ANIMATION_FALL = "fall"
const ANIMATION_FALL_LEFT = "fall_left"
const ANIMATION_FALL_RIGHT = "fall_right"
const ANIMATION_JUMP = "jump"
const ANIMATION_JUMP_LEFT = "jump_left"
const ANIMATION_JUMP_RIGHT = "jump_right"
const ANIMATION_IDLE = "idle"
const ANIMATION_LOOK_AROUND = "look_around"
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_CHASE_LEFT = "chase_left"
const ANIMATION_CHASE_RIGHT = "chase_right"
const LOOK_AROUND_FRONT_ANIMATIONS : Array[String] = [
ANIMATION_LOOK_AROUND_FRONT_1,
ANIMATION_LOOK_AROUND_FRONT_2,
]
const LOOK_AROUND_REAR_ANIMATIONS : Array[String] = [
ANIMATION_LOOK_AROUND_REAR_1,
ANIMATION_LOOK_AROUND_REAR_2,
const LOOK_AROUND_ANIMATIONS : Array[String] = [
ANIMATION_LOOK_AROUND_1,
ANIMATION_LOOK_AROUND_2,
]
+33 -119
View File
@@ -90,6 +90,14 @@ region = Rect2(64, 96, 32, 32)
atlas = ExtResource("2_g4n4l")
region = Rect2(0, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_ijx3p"]
atlas = ExtResource("2_g4n4l")
region = Rect2(0, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_nm8xp"]
atlas = ExtResource("2_g4n4l")
region = Rect2(32, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_klrad"]
atlas = ExtResource("2_g4n4l")
region = Rect2(160, 96, 32, 32)
@@ -102,22 +110,6 @@ region = Rect2(96, 96, 32, 32)
atlas = ExtResource("2_g4n4l")
region = Rect2(32, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_ijx3p"]
atlas = ExtResource("2_g4n4l")
region = Rect2(0, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_nm8xp"]
atlas = ExtResource("2_g4n4l")
region = Rect2(32, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_mocsw"]
atlas = ExtResource("2_g4n4l")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_y256a"]
atlas = ExtResource("2_g4n4l")
region = Rect2(160, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_yjsd7"]
atlas = ExtResource("2_g4n4l")
region = Rect2(64, 0, 32, 32)
@@ -158,30 +150,6 @@ region = Rect2(96, 0, 32, 32)
atlas = ExtResource("2_g4n4l")
region = Rect2(64, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_qbqct"]
atlas = ExtResource("2_g4n4l")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_8s45y"]
atlas = ExtResource("2_g4n4l")
region = Rect2(192, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_ga5mk"]
atlas = ExtResource("2_g4n4l")
region = Rect2(224, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_g4v8m"]
atlas = ExtResource("2_g4n4l")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_yu2nn"]
atlas = ExtResource("2_g4n4l")
region = Rect2(224, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_20lqo"]
atlas = ExtResource("2_g4n4l")
region = Rect2(192, 0, 32, 32)
[sub_resource type="SpriteFrames" id="SpriteFrames_2wrno"]
animations = [{
"frames": [{
@@ -247,7 +215,7 @@ animations = [{
"texture": SubResource("AtlasTexture_tjvyk")
}],
"loop": true,
"name": &"fall_down",
"name": &"fall",
"speed": 5.0
}, {
"frames": [{
@@ -255,7 +223,7 @@ animations = [{
"texture": SubResource("AtlasTexture_vecdo")
}],
"loop": true,
"name": &"fall_down_left",
"name": &"fall_left",
"speed": 5.0
}, {
"frames": [{
@@ -263,31 +231,7 @@ animations = [{
"texture": SubResource("AtlasTexture_qly8p")
}],
"loop": true,
"name": &"fall_down_right",
"speed": 5.0
}, {
"frames": [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_klrad")
}],
"loop": true,
"name": &"fall_up",
"speed": 5.0
}, {
"frames": [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_rjy0i")
}],
"loop": true,
"name": &"fall_up_left",
"speed": 5.0
}, {
"frames": [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_ps2ar")
}],
"loop": true,
"name": &"fall_up_right",
"name": &"fall_right",
"speed": 5.0
}, {
"frames": [{
@@ -301,21 +245,31 @@ animations = [{
"texture": SubResource("AtlasTexture_ijx3p")
}],
"loop": true,
"name": &"idle_front",
"name": &"idle",
"speed": 5.0
}, {
"frames": [{
"duration": 4.0,
"texture": SubResource("AtlasTexture_mocsw")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_y256a")
}, {
"duration": 5.0,
"texture": SubResource("AtlasTexture_mocsw")
"texture": SubResource("AtlasTexture_klrad")
}],
"loop": true,
"name": &"idle_rear",
"name": &"jump",
"speed": 5.0
}, {
"frames": [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_rjy0i")
}],
"loop": true,
"name": &"jump_left",
"speed": 5.0
}, {
"frames": [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_ps2ar")
}],
"loop": true,
"name": &"jump_right",
"speed": 5.0
}, {
"frames": [{
@@ -352,7 +306,7 @@ animations = [{
"texture": SubResource("AtlasTexture_vbirv")
}],
"loop": false,
"name": &"look_around_front_1",
"name": &"look_around_1",
"speed": 5.0
}, {
"frames": [{
@@ -372,47 +326,7 @@ animations = [{
"texture": SubResource("AtlasTexture_hrljr")
}],
"loop": false,
"name": &"look_around_front_2",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_qbqct")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_8s45y")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qbqct")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ga5mk")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qbqct")
}],
"loop": false,
"name": &"look_around_rear_1",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_g4v8m")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_yu2nn")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_g4v8m")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_20lqo")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_g4v8m")
}],
"loop": false,
"name": &"look_around_rear_2",
"name": &"look_around_2",
"speed": 5.0
}, {
"frames": [{
@@ -477,5 +391,5 @@ animations = [{
[node name="CultistSprite" type="AnimatedSprite2D" unique_id=351120861]
material = SubResource("ShaderMaterial_vecdo")
sprite_frames = SubResource("SpriteFrames_2wrno")
animation = &"look_around_front_1"
animation = &"fall_left"
script = ExtResource("3_ef0vi")
@@ -3,3 +3,12 @@ extends AbstractState
@export var cultist: AbstractCultist
func _physics_process(_delta: float) -> void:
if !cultist.is_on_floor():
pass
func _set_ray_cast_enable(ray_cast: RayCast2D, enabled: bool) -> void:
ray_cast.process_mode = Node.PROCESS_MODE_INHERIT if enabled else Node.PROCESS_MODE_DISABLED
@@ -0,0 +1,5 @@
extends CultistFallState
func enter() -> void:
cultist.sprite.play(CultistSprite.ANIMATION_FALL_LEFT)
@@ -0,0 +1 @@
uid://b8o0lvuy6a5q1
@@ -0,0 +1,5 @@
extends CultistFallState
func enter() -> void:
cultist.sprite.play(CultistSprite.ANIMATION_FALL_RIGHT)
@@ -0,0 +1 @@
uid://cxg54u14yb6go
@@ -0,0 +1,16 @@
class_name CultistFallState
extends CultistState
@export var look_around_state: CultistState
func enter() -> void:
cultist.sprite.play(CultistSprite.ANIMATION_FALL)
func physics_process(delta: float) -> void:
cultist.velocity += cultist.get_gravity() * delta
cultist.move_and_slide()
if cultist.is_on_floor():
switch_state.emit(look_around_state)
@@ -0,0 +1 @@
uid://bqnq6m0s4etqh
@@ -1 +1,5 @@
extends CultistState
func enter() -> void:
cultist.sprite.play(CultistSprite.ANIMATION_IDLE)
@@ -0,0 +1,12 @@
extends CultistState
func enter() -> void:
cultist.sprite.play(CultistSprite.LOOK_AROUND_ANIMATIONS.pick_random())
_set_ray_cast_enable(cultist.left_player_close_ray, true)
_set_ray_cast_enable(cultist.right_player_close_ray, true)
func exit() -> void:
_set_ray_cast_enable(cultist.left_player_close_ray, false)
_set_ray_cast_enable(cultist.right_player_close_ray, false)
@@ -0,0 +1 @@
uid://bfp8gywqqkju7
+3 -3
View File
@@ -13,9 +13,9 @@
[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"]
[ext_resource type="Script" uid="uid://c7myrm50fnpfn" path="res://game/characters/player/state_machine/falingl_state.gd" id="13_m2bqk"]
[ext_resource type="Script" uid="uid://cmimnl6jf78ao" path="res://game/characters/player/state_machine/falling_left_state.gd" id="14_2lnxg"]
[ext_resource type="Script" uid="uid://5s7ko6pcqagy" path="res://game/characters/player/state_machine/falling_right_state.gd" id="15_bfpdl"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"]
radius = 4.0
+1 -1
View File
@@ -135,7 +135,7 @@ func _on_player_timer_timeout() -> void:
_show_cutscene_haze(CUTSCENE_HAZE_TIME)
cutscene_fake_player.queue_free()
cutscene_fake_cultist.show()
cutscene_fake_cultist.play("look_around", 0.5)
cutscene_fake_cultist.play(CultistSprite.ANIMATION_LOOK_AROUND, 0.5)
cutscene_cultist_timer.start()