Added cultist move states

This commit is contained in:
2026-02-08 21:27:56 +03:00
parent 39cd68432e
commit b0e497172f
11 changed files with 222 additions and 12 deletions
@@ -6,6 +6,7 @@ extends CultistState
func enter() -> void:
cultist.sprite.play(CultistSprite.ANIMATION_IDLE)
cultist.velocity = Vector2.ZERO
func physics_process(_delta: float) -> void:
@@ -6,6 +6,7 @@ extends CultistState
func enter() -> void:
cultist.sprite.play(CultistSprite.LOOK_AROUND_ANIMATIONS.pick_random())
cultist.velocity = Vector2.ZERO
_set_ray_cast_enable(cultist.left_player_close_ray, true)
_set_ray_cast_enable(cultist.right_player_close_ray, true)
@@ -0,0 +1,7 @@
extends CultistMoveState
func _ready() -> void:
_direction = DIRECTION_LEFT
_wall_ray_cast = cultist.left_wall_ray
_player_ray_cast = cultist.left_player_distant_ray
@@ -0,0 +1 @@
uid://hgn4yll571hp
@@ -0,0 +1,7 @@
extends CultistMoveState
func _ready() -> void:
_direction = DIRECTION_RIGHT
_wall_ray_cast = cultist.right_wall_ray
_player_ray_cast = cultist.right_player_distant_ray
@@ -0,0 +1 @@
uid://bwwhmjxhg2adp
@@ -0,0 +1,51 @@
@abstract
class_name CultistMoveState
extends CultistState
const MAX_WALK_SPEED = 85
const DIRECTION_LEFT = -1
const DIRECTION_RIGHT = 1
@export var fall_state: CultistState
@export var chase_state: CultistState
@export var another_direction_move_state: CultistState
var _direction := 0
var _wall_ray_cast : RayCast2D
var _player_ray_cast : RayCast2D
func enter() -> void:
_set_ray_cast_enable(_player_ray_cast, true)
func exit() -> void:
_set_ray_cast_enable(_player_ray_cast, false)
func physics_process(delta: float) -> void:
if not cultist.is_on_floor():
switch_state.emit(fall_state)
else:
var player := _get_colliding_player(_player_ray_cast)
if player != null:
cultist.target_x = player.position.x
switch_state.emit(chase_state)
elif _wall_ray_cast.is_colliding():
switch_state.emit(another_direction_move_state)
else:
cultist.update_x_velocity(_direction, MAX_WALK_SPEED, delta)
func _get_colliding_player(ray_cast: RayCast2D) -> Player:
ray_cast.force_raycast_update()
if ray_cast.is_colliding():
var collider := ray_cast.get_collider()
if collider is Player:
return collider
return null
@@ -0,0 +1 @@
uid://lplif1gcjbai