Added cultist chase states
This commit is contained in:
+3
-1
@@ -1,7 +1,9 @@
|
||||
extends CultistMoveState
|
||||
extends CultistChaseState
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
|
||||
_direction = DIRECTION_LEFT
|
||||
_wall_ray_cast = cultist.left_wall_ray
|
||||
_player_ray_cast = cultist.left_player_distant_ray
|
||||
@@ -0,0 +1 @@
|
||||
uid://cn2lfl4kuxvjk
|
||||
@@ -0,0 +1,9 @@
|
||||
extends CultistChaseState
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
|
||||
_direction = DIRECTION_RIGHT
|
||||
_wall_ray_cast = cultist.right_wall_ray
|
||||
_player_ray_cast = cultist.right_player_distant_ray
|
||||
@@ -0,0 +1 @@
|
||||
uid://3kl84tu1vwiv
|
||||
@@ -0,0 +1,19 @@
|
||||
class_name CultistChaseState
|
||||
extends CultistMoveState
|
||||
|
||||
|
||||
@export var look_around_state: CultistState
|
||||
|
||||
|
||||
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
|
||||
|
||||
if is_equal_approx(cultist.position.x, cultist.target_x):
|
||||
switch_state.emit(look_around_state)
|
||||
else:
|
||||
cultist.update_x_velocity(_direction, cultist.MAX_CHASE_SPEED, delta)
|
||||
@@ -0,0 +1 @@
|
||||
uid://beu06w0gntfay
|
||||
@@ -5,5 +5,30 @@ extends AbstractState
|
||||
@export var cultist: AbstractCultist
|
||||
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not cultist.is_node_ready():
|
||||
await cultist.ready
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
func _chase_if_player_in_ray_cast(ray_cast: RayCast2D, chase_state: CultistState) -> bool:
|
||||
var player := _get_colliding_player(ray_cast)
|
||||
if player != null:
|
||||
cultist.target_x = player.position.x
|
||||
switch_state.emit(chase_state)
|
||||
return true
|
||||
return false
|
||||
|
||||
@@ -2,6 +2,8 @@ extends CultistState
|
||||
|
||||
|
||||
@export var fall_state: CultistState
|
||||
@export var chase_left_state: CultistState
|
||||
@export var chase_right_state: CultistState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
@@ -14,6 +16,13 @@ func enter() -> void:
|
||||
func physics_process(_delta: float) -> void:
|
||||
if not cultist.is_on_floor():
|
||||
switch_state.emit(fall_state)
|
||||
return
|
||||
|
||||
if _chase_if_player_in_ray_cast(cultist.left_player_close_ray, chase_left_state):
|
||||
return
|
||||
|
||||
if _chase_if_player_in_ray_cast(cultist.right_player_close_ray, chase_right_state):
|
||||
return
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
|
||||
@@ -3,18 +3,16 @@ 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
|
||||
|
||||
|
||||
@warning_ignore("unused_private_class_variable")
|
||||
var _direction := 0
|
||||
@warning_ignore("unused_private_class_variable")
|
||||
var _wall_ray_cast : RayCast2D
|
||||
var _player_ray_cast : RayCast2D
|
||||
|
||||
@@ -25,27 +23,3 @@ func enter() -> void:
|
||||
|
||||
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
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://lplif1gcjbai
|
||||
uid://cw5hhiv8uih7d
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
extends CultistWalkState
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
|
||||
print(cultist.left_player_distant_ray)
|
||||
|
||||
_direction = DIRECTION_LEFT
|
||||
_wall_ray_cast = cultist.left_wall_ray
|
||||
_player_ray_cast = cultist.left_player_distant_ray
|
||||
+3
-1
@@ -1,7 +1,9 @@
|
||||
extends CultistMoveState
|
||||
extends CultistWalkState
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
|
||||
_direction = DIRECTION_RIGHT
|
||||
_wall_ray_cast = cultist.right_wall_ray
|
||||
_player_ray_cast = cultist.right_player_distant_ray
|
||||
@@ -0,0 +1,20 @@
|
||||
@abstract
|
||||
class_name CultistWalkState
|
||||
extends CultistMoveState
|
||||
|
||||
|
||||
@export var chase_state: CultistState
|
||||
@export var another_direction_walk_state: CultistState
|
||||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
if not cultist.is_on_floor():
|
||||
switch_state.emit(fall_state)
|
||||
else:
|
||||
if not _chase_if_player_in_ray_cast(_player_ray_cast, chase_state):
|
||||
if _wall_ray_cast.is_colliding():
|
||||
var stream := SoundManager.sfx_stream_player_lost
|
||||
SoundManager.play_sfx_stream(stream, cultist.global_position)
|
||||
switch_state.emit(another_direction_walk_state)
|
||||
else:
|
||||
cultist.update_x_velocity(_direction, cultist.MAX_WALK_SPEED, delta)
|
||||
@@ -0,0 +1 @@
|
||||
uid://lplif1gcjbai
|
||||
Reference in New Issue
Block a user