Added cultist jump state
This commit is contained in:
@@ -5,6 +5,9 @@ extends CharacterBody2D
|
|||||||
const MAX_WALK_SPEED = 85
|
const MAX_WALK_SPEED = 85
|
||||||
const MAX_CHASE_SPEED = 170
|
const MAX_CHASE_SPEED = 170
|
||||||
const ACCELERATION = 600.0
|
const ACCELERATION = 600.0
|
||||||
|
const JUMP_VELOCITY = 333.0
|
||||||
|
const JUMP_GRAVITY_FACTOR = 1.0
|
||||||
|
const FALL_GRAVITY_FACTOR = 1.5
|
||||||
|
|
||||||
|
|
||||||
var target_x := 0.0
|
var target_x := 0.0
|
||||||
@@ -45,5 +48,9 @@ func update_x_velocity(direction: int, max_speed: float, delta: float) -> void:
|
|||||||
velocity.x = move_toward(velocity.x, direction * max_speed, ACCELERATION * delta)
|
velocity.x = move_toward(velocity.x, direction * max_speed, ACCELERATION * delta)
|
||||||
|
|
||||||
|
|
||||||
|
func get_gravity_factor() -> float:
|
||||||
|
return JUMP_GRAVITY_FACTOR if velocity.y < 0.0 else FALL_GRAVITY_FACTOR
|
||||||
|
|
||||||
|
|
||||||
func _set_ray_cast_enable(ray_cast: RayCast2D, enabled: bool) -> void:
|
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
|
ray_cast.process_mode = Node.PROCESS_MODE_INHERIT if enabled else Node.PROCESS_MODE_DISABLED
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
[ext_resource type="Script" uid="uid://hgn4yll571hp" path="res://game/characters/enemies/state_machine/walk_left_state.gd" id="11_lh753"]
|
[ext_resource type="Script" uid="uid://hgn4yll571hp" path="res://game/characters/enemies/state_machine/walk_left_state.gd" id="11_lh753"]
|
||||||
[ext_resource type="Script" uid="uid://bwwhmjxhg2adp" path="res://game/characters/enemies/state_machine/walk_right_state.gd" id="12_lh753"]
|
[ext_resource type="Script" uid="uid://bwwhmjxhg2adp" path="res://game/characters/enemies/state_machine/walk_right_state.gd" id="12_lh753"]
|
||||||
[ext_resource type="Script" uid="uid://cn2lfl4kuxvjk" path="res://game/characters/enemies/state_machine/chase_left_state.gd" id="13_42ivi"]
|
[ext_resource type="Script" uid="uid://cn2lfl4kuxvjk" path="res://game/characters/enemies/state_machine/chase_left_state.gd" id="13_42ivi"]
|
||||||
|
[ext_resource type="Script" uid="uid://cqlym4lqahsd3" path="res://game/characters/enemies/state_machine/cultist_jump_left_state.gd" id="14_42ivi"]
|
||||||
[ext_resource type="Script" uid="uid://3kl84tu1vwiv" path="res://game/characters/enemies/state_machine/chase_right_state.gd" id="14_cqp7f"]
|
[ext_resource type="Script" uid="uid://3kl84tu1vwiv" path="res://game/characters/enemies/state_machine/chase_right_state.gd" id="14_cqp7f"]
|
||||||
|
[ext_resource type="Script" uid="uid://cf52bjcpasft1" path="res://game/characters/enemies/state_machine/cultist_jump_right_state.gd" id="15_cqp7f"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_mocsw"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_mocsw"]
|
||||||
radius = 4.0
|
radius = 4.0
|
||||||
@@ -120,14 +122,26 @@ another_direction_walk_state = NodePath("../WalkLeftState")
|
|||||||
fall_state = NodePath("../FallRightState")
|
fall_state = NodePath("../FallRightState")
|
||||||
cultist = NodePath("../..")
|
cultist = NodePath("../..")
|
||||||
|
|
||||||
[node name="ChaseLeftState" parent="CultistStateMachine" unique_id=209480830 node_paths=PackedStringArray("look_around_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
[node name="ChaseLeftState" parent="CultistStateMachine" unique_id=209480830 node_paths=PackedStringArray("look_around_state", "jump_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||||
script = ExtResource("13_42ivi")
|
script = ExtResource("13_42ivi")
|
||||||
look_around_state = NodePath("../LookAroundState")
|
look_around_state = NodePath("../LookAroundState")
|
||||||
|
jump_state = NodePath("../JumpLeftState")
|
||||||
fall_state = NodePath("../FallState")
|
fall_state = NodePath("../FallState")
|
||||||
cultist = NodePath("../..")
|
cultist = NodePath("../..")
|
||||||
|
|
||||||
[node name="ChaseRightState" parent="CultistStateMachine" unique_id=383038915 node_paths=PackedStringArray("look_around_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
[node name="ChaseRightState" parent="CultistStateMachine" unique_id=383038915 node_paths=PackedStringArray("look_around_state", "jump_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||||
script = ExtResource("14_cqp7f")
|
script = ExtResource("14_cqp7f")
|
||||||
look_around_state = NodePath("../LookAroundState")
|
look_around_state = NodePath("../LookAroundState")
|
||||||
|
jump_state = NodePath(".")
|
||||||
fall_state = NodePath("../FallState")
|
fall_state = NodePath("../FallState")
|
||||||
cultist = NodePath("../..")
|
cultist = NodePath("../..")
|
||||||
|
|
||||||
|
[node name="JumpLeftState" parent="CultistStateMachine" unique_id=739226464 node_paths=PackedStringArray("fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||||
|
script = ExtResource("14_42ivi")
|
||||||
|
fall_state = NodePath("../FallLeftState")
|
||||||
|
cultist = NodePath("../..")
|
||||||
|
|
||||||
|
[node name="JumpRightState" parent="CultistStateMachine" unique_id=756126836 node_paths=PackedStringArray("fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||||
|
script = ExtResource("15_cqp7f")
|
||||||
|
fall_state = NodePath("../FallRightState")
|
||||||
|
cultist = NodePath("../..")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ extends CultistMoveState
|
|||||||
|
|
||||||
|
|
||||||
@export var look_around_state: CultistState
|
@export var look_around_state: CultistState
|
||||||
|
@export var jump_state: CultistState
|
||||||
|
|
||||||
|
|
||||||
func physics_process(delta: float) -> void:
|
func physics_process(delta: float) -> void:
|
||||||
@@ -14,8 +15,10 @@ func physics_process(delta: float) -> void:
|
|||||||
if player != null:
|
if player != null:
|
||||||
cultist.target_x = player.position.x
|
cultist.target_x = player.position.x
|
||||||
|
|
||||||
if _is_target_reached() or _wall_ray_cast.is_colliding():
|
if _is_target_reached():
|
||||||
switch_state.emit(look_around_state)
|
switch_state.emit(look_around_state)
|
||||||
|
elif _wall_ray_cast.is_colliding():
|
||||||
|
switch_state.emit(jump_state)
|
||||||
else:
|
else:
|
||||||
cultist.update_x_velocity(_direction, cultist.MAX_CHASE_SPEED, delta)
|
cultist.update_x_velocity(_direction, cultist.MAX_CHASE_SPEED, delta)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
extends CultistJumpState
|
||||||
|
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
super.enter()
|
||||||
|
_direction = DIRECTION_LEFT
|
||||||
|
cultist.sprite.play(CultistSprite.ANIMATION_JUMP_LEFT)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://cqlym4lqahsd3
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
extends CultistJumpState
|
||||||
|
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
super.enter()
|
||||||
|
_direction = DIRECTION_RIGHT
|
||||||
|
cultist.sprite.play(CultistSprite.ANIMATION_JUMP_RIGHT)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://cf52bjcpasft1
|
||||||
@@ -2,6 +2,10 @@ class_name CultistState
|
|||||||
extends AbstractState
|
extends AbstractState
|
||||||
|
|
||||||
|
|
||||||
|
const DIRECTION_LEFT = -1
|
||||||
|
const DIRECTION_RIGHT = 1
|
||||||
|
|
||||||
|
|
||||||
@export var cultist: AbstractCultist
|
@export var cultist: AbstractCultist
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
@abstract
|
||||||
|
class_name CultistJumpState
|
||||||
|
extends CultistState
|
||||||
|
|
||||||
|
|
||||||
|
@export var fall_state: CultistState
|
||||||
|
|
||||||
|
|
||||||
|
var _direction := 0
|
||||||
|
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
cultist.velocity.y -= cultist.JUMP_VELOCITY
|
||||||
|
|
||||||
|
|
||||||
|
func physics_process(delta: float) -> void:
|
||||||
|
if cultist.velocity.y > 0:
|
||||||
|
switch_state.emit(fall_state)
|
||||||
|
else:
|
||||||
|
cultist.velocity += cultist.get_gravity() * cultist.get_gravity_factor() * delta
|
||||||
|
cultist.update_x_velocity(_direction, cultist.MAX_WALK_SPEED, delta)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://cxvl7a8o7bc1p
|
||||||
@@ -3,10 +3,6 @@ class_name CultistMoveState
|
|||||||
extends CultistState
|
extends CultistState
|
||||||
|
|
||||||
|
|
||||||
const DIRECTION_LEFT = -1
|
|
||||||
const DIRECTION_RIGHT = 1
|
|
||||||
|
|
||||||
|
|
||||||
@export var fall_state: CultistState
|
@export var fall_state: CultistState
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user