Reworked Cultist

This commit is contained in:
2026-06-20 21:58:27 +03:00
parent e1e2cb3bd1
commit e2c5cd35ec
32 changed files with 948 additions and 488 deletions
@@ -1,10 +0,0 @@
class_name AbstractColorCultist
extends AbstractCultist
@onready var collision_switcher : CollisionSwitcher = $CollisionSwitcher
func _ready() -> void:
super._ready()
collision_switcher.add_material(sprite.material)
@@ -1 +0,0 @@
uid://das7ujanefsn0
@@ -1,17 +0,0 @@
[gd_scene format=3 uid="uid://d37eyum03h83i"]
[ext_resource type="PackedScene" uid="uid://bx0luh4vdob3q" path="res://game/characters/enemies/abstract_cultist.tscn" id="1_12hr0"]
[ext_resource type="Script" uid="uid://das7ujanefsn0" path="res://game/characters/enemies/abstract_color_cultist.gd" id="2_rd56i"]
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="3_e5cea"]
[sub_resource type="ViewportTexture" id="ViewportTexture_f5md8"]
viewport_path = NodePath("SubViewport")
[node name="AbstractColorCultist" unique_id=644641841 instance=ExtResource("1_12hr0")]
script = ExtResource("2_rd56i")
[node name="CultistSprite" parent="." index="1" unique_id=797412888]
texture = SubResource("ViewportTexture_f5md8")
[node name="CollisionSwitcher" parent="." index="2" unique_id=991274552 node_paths=PackedStringArray("objects") instance=ExtResource("3_e5cea")]
objects = [NodePath("..")]
@@ -1,71 +0,0 @@
class_name AbstractCultist
extends CharacterBody2D
const MAX_WALK_SPEED = 85
const MAX_CHASE_SPEED = 170
const ACCELERATION = 600.0
const JUMP_VELOCITY = 222.0
const JUMP_GRAVITY_FACTOR = 1.0
const FALL_GRAVITY_FACTOR = 1.5
var target_x := 0.0
@onready var sprite : Sprite2D = $CultistSprite
@onready var water_splash : GPUParticles2D = $WaterSplash
@onready var animated_sprite : AnimatedSprite2D = $SubViewport/CultistSprite
@onready var left_wall_high_ray : RayCast2D = $WallCheckHigh/LeftWallRay
@onready var right_wall_high_ray : RayCast2D = $WallCheckHigh/RightWallRay
@onready var left_wall_low_ray : RayCast2D = $WallCheckLow/LeftWallRay
@onready var right_wall_low_ray : RayCast2D = $WallCheckLow/RightWallRay
@onready var left_player_close_ray : RayCast2D = $%LeftPlayerCloseRay
@onready var right_player_close_ray : RayCast2D = $%RightPlayerCloseRay
@onready var left_player_distant_ray : RayCast2D = $%LeftPlayerDistantRay
@onready var right_player_distant_ray : RayCast2D = $%RightPlayerDistantRay
@onready var state_machine : CultistStateMachine = $CultistStateMachine
@onready var chase_left_state : CultistState = $CultistStateMachine/ChaseLeftState
@onready var chase_right_state : CultistState = $CultistStateMachine/ChaseRightState
@onready var look_around_state : CultistState = $CultistStateMachine/LookAroundState
func _ready() -> void:
_set_ray_cast_enable(left_player_close_ray, false)
_set_ray_cast_enable(right_player_close_ray, false)
_set_ray_cast_enable(left_player_distant_ray, false)
_set_ray_cast_enable(right_player_distant_ray, false)
state_machine.init()
func _physics_process(delta: float) -> void:
state_machine.physics_process(delta)
move_and_slide()
func kill(type := KillingArea.Type.None) -> void:
match type:
KillingArea.Type.Water:
SoundManager.play_sfx_stream(SoundManager.sfx_stream_splash, global_position)
water_splash.finished.connect(queue_free)
water_splash.restart()
_:
queue_free()
func update_x_velocity(direction: int, max_speed: float, delta: float) -> void:
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:
ray_cast.process_mode = Node.PROCESS_MODE_INHERIT if enabled else Node.PROCESS_MODE_DISABLED
-2
View File
@@ -1,2 +0,0 @@
class_name BlackCultist
extends AbstractColorCultist
@@ -1 +0,0 @@
uid://c2knsjcp6faf6
@@ -1,43 +0,0 @@
[gd_scene format=3 uid="uid://cutjutvd8dqqc"]
[ext_resource type="PackedScene" uid="uid://d37eyum03h83i" path="res://game/characters/enemies/abstract_color_cultist.tscn" id="1_gj2ks"]
[ext_resource type="Script" uid="uid://c2knsjcp6faf6" path="res://game/characters/enemies/black_cultist.gd" id="2_332ds"]
[ext_resource type="Material" uid="uid://dggr8t4b30e3n" path="res://game/materials/enemy_black.tres" id="3_v1if5"]
[sub_resource type="ViewportTexture" id="ViewportTexture_q6bby"]
viewport_path = NodePath("SubViewport")
[node name="BlackCultist" unique_id=1910124567 instance=ExtResource("1_gj2ks")]
collision_layer = 4
collision_mask = 3
script = ExtResource("2_332ds")
[node name="CultistSprite" parent="." index="0" unique_id=797412888]
material = ExtResource("3_v1if5")
texture = SubResource("ViewportTexture_q6bby")
[node name="CollisionSwitcher" parent="." index="2" unique_id=991274552]
initial_state = 0
[node name="LeftWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="0" unique_id=521416854]
collision_mask = 3
[node name="RightWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="1" unique_id=1457669135]
collision_mask = 3
[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="0" unique_id=947570027]
target_position = Vector2(-32, 0)
collision_mask = 11
[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="1" unique_id=1559118218]
target_position = Vector2(32, 0)
collision_mask = 11
[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="0" unique_id=1491085518]
collision_mask = 11
[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="1" unique_id=1377654831]
collision_mask = 11
[node name="KillingArea" parent="." index="8" unique_id=1891922549]
collision_mask = 8
+144
View File
@@ -0,0 +1,144 @@
@tool
class_name Cultist
extends CharacterBody2D
enum Type {
White,
Black,
Gray,
}
const MAX_WALK_SPEED = 85
const MAX_CHASE_SPEED = 170
const ACCELERATION = 600.0
const JUMP_VELOCITY = 222.0
const JUMP_GRAVITY_FACTOR = 1.0
const FALL_GRAVITY_FACTOR = 1.5
@export var type := Type.White:
set(value):
type = value
if is_node_ready():
_updated_sprite()
_updated_collision()
var target_x := 0.0
@onready var sprite : Sprite2D = $CultistSprite
@onready var animated_sprite : AnimatedSprite2D = $CultistSprite.animated_sprite
@onready var water_splash : GPUParticles2D = $WaterSplash
@onready var killing_area : KillingArea = $KillingArea
@onready var left_wall_high_ray : RayCast2D = $WallCheckHigh/LeftWallRay
@onready var right_wall_high_ray : RayCast2D = $WallCheckHigh/RightWallRay
@onready var left_wall_low_ray : RayCast2D = $WallCheckLow/LeftWallRay
@onready var right_wall_low_ray : RayCast2D = $WallCheckLow/RightWallRay
@onready var left_player_close_ray : RayCast2D = $%LeftPlayerCloseRay
@onready var right_player_close_ray : RayCast2D = $%RightPlayerCloseRay
@onready var left_player_distant_ray : RayCast2D = $%LeftPlayerDistantRay
@onready var right_player_distant_ray : RayCast2D = $%RightPlayerDistantRay
@onready var wall_rays : Array[RayCast2D] = [
left_wall_high_ray, right_wall_high_ray,
left_wall_low_ray, right_wall_low_ray,
]
@onready var player_rays : Array[RayCast2D] = [
left_player_close_ray, right_player_close_ray,
left_player_distant_ray, right_player_distant_ray,
]
@onready var state_machine : CultistStateMachine = $CultistStateMachine
@onready var chase_left_state : CultistState = $CultistStateMachine/ChaseLeftState
@onready var chase_right_state : CultistState = $CultistStateMachine/ChaseRightState
@onready var look_around_state : CultistState = $CultistStateMachine/LookAroundState
func _ready() -> void:
_updated_sprite()
_updated_collision()
if not Engine.is_editor_hint():
_set_ray_cast_enable(left_player_close_ray, false)
_set_ray_cast_enable(right_player_close_ray, false)
_set_ray_cast_enable(left_player_distant_ray, false)
_set_ray_cast_enable(right_player_distant_ray, false)
state_machine.init()
func _physics_process(delta: float) -> void:
if not Engine.is_editor_hint():
state_machine.physics_process(delta)
move_and_slide()
func kill(killing_type := KillingArea.Type.None) -> void:
match killing_type:
KillingArea.Type.Water:
SoundManager.play_sfx_stream(SoundManager.sfx_stream_splash, global_position)
water_splash.finished.connect(queue_free)
water_splash.restart()
_:
queue_free()
func update_x_velocity(direction: int, max_speed: float, delta: float) -> void:
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 _updated_sprite() -> void:
sprite.type = type
func _updated_collision() -> void:
const C = CollisionSwitcher.Collisions
var layer: int
var world_mask: int
var player_mask: int
match type:
Type.White:
layer = C.WHITE_ENEMY
world_mask = C.WHITE_WORLD
player_mask = C.WHITE_PLAYER
Type.Black:
layer = C.BLACK_ENEMY
world_mask = C.BLACK_WORLD
player_mask = C.BLACK_PLAYER
Type.Gray:
layer = C.GREY_ENEMY
world_mask = C.WHITE_WORLD | C.BLACK_WORLD
player_mask = C.WHITE_PLAYER | C.BLACK_PLAYER
_:
return
world_mask |= C.GREY_WORLD
collision_layer = layer
_set_mask(world_mask, player_mask)
func _set_mask(world_mask: int, player_mask: int) -> void:
collision_mask = world_mask
for ray in wall_rays:
ray.collision_mask = world_mask
for ray in player_rays:
ray.collision_mask = world_mask | player_mask
killing_area.collision_mask = player_mask
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
if Engine.is_editor_hint():
if enabled: ray_cast.show()
else: ray_cast.hide()
@@ -1,23 +1,38 @@
[gd_scene format=3 uid="uid://bx0luh4vdob3q"]
[ext_resource type="Script" uid="uid://but5aeh7y1s0f" path="res://game/characters/enemies/abstract_cultist.gd" id="1_2wrno"]
[ext_resource type="PackedScene" uid="uid://dtxiercm8dsfm" path="res://game/characters/enemies/cultist_sprite.tscn" id="2_tjvyk"]
[ext_resource type="PackedScene" uid="uid://8yd8f5x1hujv" path="res://game/characters/water_splash.tscn" id="2_w1t0g"]
[ext_resource type="PackedScene" uid="uid://dike8xgbqdut2" path="res://game/killing_area.tscn" id="3_tjvyk"]
[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://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"]
[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://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://cf52bjcpasft1" path="res://game/characters/enemies/state_machine/cultist_jump_right_state.gd" id="15_cqp7f"]
[ext_resource type="Script" uid="uid://but5aeh7y1s0f" path="res://game/characters/enemies/cultist.gd" id="1_ah13v"]
[ext_resource type="PackedScene" uid="uid://8yd8f5x1hujv" path="res://game/characters/water_splash.tscn" id="2_go1hq"]
[ext_resource type="PackedScene" uid="uid://dtxiercm8dsfm" path="res://game/characters/enemies/cultist_sprite.tscn" id="3_mbt3t"]
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="4_ul6ar"]
[ext_resource type="PackedScene" uid="uid://dike8xgbqdut2" path="res://game/killing_area.tscn" id="5_500rx"]
[ext_resource type="PackedScene" uid="uid://bg7k6ovbk1xgm" path="res://game/characters/enemies/state_machine/cultist_state_machine.tscn" id="6_oqd45"]
[ext_resource type="PackedScene" uid="uid://bq1v55jv4c6qe" path="res://game/characters/enemies/state_machine/cultist_state.tscn" id="7_nsxyj"]
[ext_resource type="Script" uid="uid://bqnq6m0s4etqh" path="res://game/characters/enemies/state_machine/fall_state.gd" id="8_h77eg"]
[ext_resource type="Script" uid="uid://b8o0lvuy6a5q1" path="res://game/characters/enemies/state_machine/fall_left_state.gd" id="9_uasba"]
[ext_resource type="Script" uid="uid://cxg54u14yb6go" path="res://game/characters/enemies/state_machine/fall_right_state.gd" id="10_mye2w"]
[ext_resource type="Script" uid="uid://bfp8gywqqkju7" path="res://game/characters/enemies/state_machine/look_around_state.gd" id="11_rqqg0"]
[ext_resource type="Script" uid="uid://hgn4yll571hp" path="res://game/characters/enemies/state_machine/walk_left_state.gd" id="12_vm7uu"]
[ext_resource type="Script" uid="uid://bwwhmjxhg2adp" path="res://game/characters/enemies/state_machine/walk_right_state.gd" id="13_x8b3k"]
[ext_resource type="Script" uid="uid://cn2lfl4kuxvjk" path="res://game/characters/enemies/state_machine/chase_left_state.gd" id="14_d5aal"]
[ext_resource type="Script" uid="uid://3kl84tu1vwiv" path="res://game/characters/enemies/state_machine/chase_right_state.gd" id="15_1yxn0"]
[ext_resource type="Script" uid="uid://cqlym4lqahsd3" path="res://game/characters/enemies/state_machine/cultist_jump_left_state.gd" id="16_11eub"]
[ext_resource type="Script" uid="uid://cf52bjcpasft1" path="res://game/characters/enemies/state_machine/cultist_jump_right_state.gd" id="17_6hjcx"]
[sub_resource type="ViewportTexture" id="ViewportTexture_cqp7f"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ah13v"]
resource_local_to_scene = true
shader = ExtResource("4_ul6ar")
shader_parameter/black_color = Color(0, 0, 0, 1)
shader_parameter/white_color = Color(1, 1, 1, 1)
shader_parameter/switch_colors = false
shader_parameter/threshold = 0.5
shader_parameter/speed = 3.0
shader_parameter/intensity = 1.0
shader_parameter/scale = 5.0
shader_parameter/seed = 0.0
shader_parameter/direction = Vector2(0, 1)
shader_parameter/use_world_pos = false
[sub_resource type="ViewportTexture" id="ViewportTexture_go1hq"]
viewport_path = NodePath("SubViewport")
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_mocsw"]
@@ -28,24 +43,18 @@ height = 28.0
radius = 4.0
height = 28.0
[node name="AbstractCultist" type="CharacterBody2D" unique_id=1676614852]
collision_layer = 0
script = ExtResource("1_2wrno")
[node name="Cultist" type="CharacterBody2D" unique_id=1676614852]
collision_layer = 64
collision_mask = 33
script = ExtResource("1_ah13v")
[node name="WaterSplash" parent="." unique_id=658940825 instance=ExtResource("2_w1t0g")]
[node name="WaterSplash" parent="." unique_id=658940825 instance=ExtResource("2_go1hq")]
position = Vector2(0, -14)
[node name="CultistSprite" type="Sprite2D" parent="." unique_id=797412888]
texture = SubResource("ViewportTexture_cqp7f")
[node name="SubViewport" type="SubViewport" parent="." unique_id=903152885]
transparent_bg = true
canvas_item_default_texture_filter = 0
size = Vector2i(32, 32)
[node name="CultistSprite" parent="SubViewport" unique_id=1997264413 instance=ExtResource("2_tjvyk")]
material = null
position = Vector2(16, 16)
[node name="CultistSprite" parent="." unique_id=1997264413 instance=ExtResource("3_mbt3t")]
material = SubResource("ShaderMaterial_ah13v")
position = Vector2(0, 1)
texture = SubResource("ViewportTexture_go1hq")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=185651284]
position = Vector2(0, 2)
@@ -56,18 +65,22 @@ position = Vector2(0, -8)
[node name="LeftWallRay" type="RayCast2D" parent="WallCheckHigh" unique_id=1026693538]
target_position = Vector2(-16, 0)
collision_mask = 33
[node name="RightWallRay" type="RayCast2D" parent="WallCheckHigh" unique_id=1129233918]
target_position = Vector2(16, 0)
collision_mask = 33
[node name="WallCheckLow" type="Node2D" parent="." unique_id=782156094]
position = Vector2(0, 9)
[node name="LeftWallRay" type="RayCast2D" parent="WallCheckLow" unique_id=521416854]
target_position = Vector2(-16, 0)
collision_mask = 33
[node name="RightWallRay" type="RayCast2D" parent="WallCheckLow" unique_id=1457669135]
target_position = Vector2(16, 0)
collision_mask = 33
[node name="PlayerCloseCheck" type="Node2D" parent="." unique_id=1593775088]
position = Vector2(0, -8)
@@ -75,12 +88,12 @@ position = Vector2(0, -8)
[node name="LeftPlayerCloseRay" type="RayCast2D" parent="PlayerCloseCheck" unique_id=947570027]
unique_name_in_owner = true
target_position = Vector2(-48, 0)
collision_mask = 0
collision_mask = 161
[node name="RightPlayerCloseRay" type="RayCast2D" parent="PlayerCloseCheck" unique_id=1559118218]
unique_name_in_owner = true
target_position = Vector2(48, 0)
collision_mask = 0
collision_mask = 161
[node name="PlayerDistantCheck" type="Node2D" parent="." unique_id=1597489123]
position = Vector2(0, -8)
@@ -88,43 +101,43 @@ position = Vector2(0, -8)
[node name="LeftPlayerDistantRay" type="RayCast2D" parent="PlayerDistantCheck" unique_id=1491085518]
unique_name_in_owner = true
target_position = Vector2(-320, 0)
collision_mask = 0
collision_mask = 161
[node name="RightPlayerDistantRay" type="RayCast2D" parent="PlayerDistantCheck" unique_id=1377654831]
unique_name_in_owner = true
target_position = Vector2(320, 0)
collision_mask = 0
collision_mask = 161
[node name="KillingArea" parent="." unique_id=1891922549 instance=ExtResource("3_tjvyk")]
collision_mask = 0
[node name="KillingArea" parent="." unique_id=1891922549 instance=ExtResource("5_500rx")]
collision_mask = 128
[node name="CollisionShape2D" type="CollisionShape2D" parent="KillingArea" unique_id=1710758452]
position = Vector2(0, 2)
shape = SubResource("CapsuleShape2D_tjvyk")
[node name="CultistStateMachine" parent="." unique_id=633169960 node_paths=PackedStringArray("cultist", "initial_state") instance=ExtResource("4_yu28k")]
[node name="CultistStateMachine" parent="." unique_id=633169960 node_paths=PackedStringArray("cultist", "initial_state") instance=ExtResource("6_oqd45")]
cultist = NodePath("..")
initial_state = NodePath("WalkLeftState")
initial_state = NodePath("LookAroundState")
[node name="FallState" parent="CultistStateMachine" unique_id=1764777802 node_paths=PackedStringArray("look_around_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("7_7tkj8")
[node name="FallState" parent="CultistStateMachine" unique_id=1764777802 node_paths=PackedStringArray("look_around_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("8_h77eg")
look_around_state = NodePath("../LookAroundState")
cultist = NodePath("../..")
[node name="FallLeftState" parent="CultistStateMachine" unique_id=1011952297 node_paths=PackedStringArray("fall_state", "look_around_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("8_2opx4")
[node name="FallLeftState" parent="CultistStateMachine" unique_id=1011952297 node_paths=PackedStringArray("fall_state", "look_around_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("9_uasba")
fall_state = NodePath("../FallState")
look_around_state = NodePath("../LookAroundState")
cultist = NodePath("../..")
[node name="FallRightState" parent="CultistStateMachine" unique_id=1932915544 node_paths=PackedStringArray("fall_state", "look_around_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("9_lu83c")
[node name="FallRightState" parent="CultistStateMachine" unique_id=1932915544 node_paths=PackedStringArray("fall_state", "look_around_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("10_mye2w")
fall_state = NodePath("../FallState")
look_around_state = NodePath("../LookAroundState")
cultist = NodePath("../..")
[node name="LookAroundState" parent="CultistStateMachine" unique_id=2025927882 node_paths=PackedStringArray("fall_state", "walk_left_state", "walk_right_state", "chase_left_state", "chase_right_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("10_lu83c")
[node name="LookAroundState" parent="CultistStateMachine" unique_id=2025927882 node_paths=PackedStringArray("fall_state", "walk_left_state", "walk_right_state", "chase_left_state", "chase_right_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("11_rqqg0")
fall_state = NodePath("../FallState")
walk_left_state = NodePath("../WalkLeftState")
walk_right_state = NodePath("../WalkRightState")
@@ -132,40 +145,40 @@ chase_left_state = NodePath("../ChaseLeftState")
chase_right_state = NodePath("../ChaseRightState")
cultist = NodePath("../..")
[node name="WalkLeftState" parent="CultistStateMachine" unique_id=276543931 node_paths=PackedStringArray("chase_state", "another_direction_walk_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("11_lh753")
[node name="WalkLeftState" parent="CultistStateMachine" unique_id=276543931 node_paths=PackedStringArray("chase_state", "another_direction_walk_state", "fall_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("12_vm7uu")
chase_state = NodePath("../ChaseLeftState")
another_direction_walk_state = NodePath("../WalkRightState")
fall_state = NodePath("../FallLeftState")
cultist = NodePath("../..")
[node name="WalkRightState" parent="CultistStateMachine" unique_id=1671686910 node_paths=PackedStringArray("chase_state", "another_direction_walk_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("12_lh753")
[node name="WalkRightState" parent="CultistStateMachine" unique_id=1671686910 node_paths=PackedStringArray("chase_state", "another_direction_walk_state", "fall_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("13_x8b3k")
chase_state = NodePath("../ChaseRightState")
another_direction_walk_state = NodePath("../WalkLeftState")
fall_state = NodePath("../FallRightState")
cultist = NodePath("../..")
[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")
[node name="ChaseLeftState" parent="CultistStateMachine" unique_id=209480830 node_paths=PackedStringArray("look_around_state", "jump_state", "fall_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("14_d5aal")
look_around_state = NodePath("../LookAroundState")
jump_state = NodePath("../JumpLeftState")
fall_state = NodePath("../FallState")
cultist = NodePath("../..")
[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")
[node name="ChaseRightState" parent="CultistStateMachine" unique_id=383038915 node_paths=PackedStringArray("look_around_state", "jump_state", "fall_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("15_1yxn0")
look_around_state = NodePath("../LookAroundState")
jump_state = NodePath("../JumpRightState")
fall_state = NodePath("../FallState")
cultist = NodePath("../..")
[node name="JumpLeftState" parent="CultistStateMachine" unique_id=739226464 node_paths=PackedStringArray("chase_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("14_42ivi")
[node name="JumpLeftState" parent="CultistStateMachine" unique_id=739226464 node_paths=PackedStringArray("chase_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("16_11eub")
chase_state = NodePath("../ChaseLeftState")
cultist = NodePath("../..")
[node name="JumpRightState" parent="CultistStateMachine" unique_id=756126836 node_paths=PackedStringArray("chase_state", "cultist") instance=ExtResource("5_tu2pi")]
script = ExtResource("15_cqp7f")
[node name="JumpRightState" parent="CultistStateMachine" unique_id=756126836 node_paths=PackedStringArray("chase_state", "cultist") instance=ExtResource("7_nsxyj")]
script = ExtResource("17_6hjcx")
chase_state = NodePath("../ChaseRightState")
cultist = NodePath("../..")
+63 -1
View File
@@ -1,7 +1,31 @@
@tool
class_name CultistSprite
extends AnimatedSprite2D
extends Sprite2D
enum View {
Front,
Right,
Left,
}
const SHADER_SWITCH_COLORS = "shader_parameter/switch_colors"
const SHADER_INTENSITY = "shader_parameter/intensity"
const SHADER_SEED = "shader_parameter/seed"
const is_color_switched : Dictionary[Cultist.Type, bool] = {
Cultist.Type.White: false,
Cultist.Type.Black: true,
Cultist.Type.Gray: false,
}
const intensity : Dictionary[Cultist.Type, float] = {
Cultist.Type.White: 1.0,
Cultist.Type.Black: 1.0,
Cultist.Type.Gray: 0.5,
}
const ANIMATION_FALL = "fall"
const ANIMATION_FALL_LEFT = "fall_left"
const ANIMATION_FALL_RIGHT = "fall_right"
@@ -21,3 +45,41 @@ const LOOK_AROUND_ANIMATIONS : Array[String] = [
ANIMATION_LOOK_AROUND_1,
ANIMATION_LOOK_AROUND_2,
]
@export var type := Cultist.Type.White:
set(value):
type = value
if is_node_ready():
_update_type()
@export var view := View.Front:
set(value):
view = value
if is_node_ready():
_update_view()
@onready var animated_sprite : AnimatedSprite2D = $SubViewport/AnimatedSprite2D
func _ready() -> void:
_update_type()
_update_view()
if not Engine.is_editor_hint():
material.set(SHADER_SEED, randf())
func _update_type() -> void:
material.set(SHADER_INTENSITY, intensity[type])
material.set(SHADER_SWITCH_COLORS, is_color_switched[type])
func _update_view() -> void:
match view:
View.Front:
animated_sprite.animation = ANIMATION_IDLE
View.Left:
animated_sprite.animation = ANIMATION_WALK_LEFT
View.Right:
animated_sprite.animation = ANIMATION_WALK_RIGHT
@@ -1 +1 @@
uid://dkxmwkjttbf2d
uid://bmk0r5ovfi60u
+29 -28
View File
@@ -1,18 +1,11 @@
[gd_scene format=3 uid="uid://dtxiercm8dsfm"]
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="1_ew6gn"]
[ext_resource type="Material" uid="uid://dwgqr50guokxg" path="res://game/materials/cultist.tres" id="1_1pedr"]
[ext_resource type="Script" uid="uid://bmk0r5ovfi60u" path="res://game/characters/enemies/cultist_sprite.gd" id="2_ew6gn"]
[ext_resource type="Texture2D" uid="uid://drk8j57acajrq" path="res://images/characters/cultist.png" id="2_g4n4l"]
[ext_resource type="Script" uid="uid://dkxmwkjttbf2d" path="res://game/characters/enemies/cultist_sprite.gd" id="3_ef0vi"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_vecdo"]
shader = ExtResource("1_ew6gn")
shader_parameter/black_color = Color(0, 0, 0, 1)
shader_parameter/white_color = Color(1, 1, 1, 1)
shader_parameter/switch_colors = false
shader_parameter/threshold = 0.5
shader_parameter/speed = 5.0
shader_parameter/intensity = 1.0
shader_parameter/scale = 20.0
[sub_resource type="ViewportTexture" id="ViewportTexture_bhunq"]
viewport_path = NodePath("SubViewport")
[sub_resource type="AtlasTexture" id="AtlasTexture_l58xb"]
atlas = ExtResource("2_g4n4l")
@@ -177,7 +170,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_x6npu")
}],
"loop": true,
"loop": 1,
"name": &"chase_left",
"speed": 20.0
}, {
@@ -206,7 +199,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_0xs27")
}],
"loop": true,
"loop": 1,
"name": &"chase_right",
"speed": 20.0
}, {
@@ -214,7 +207,7 @@ animations = [{
"duration": 10.0,
"texture": SubResource("AtlasTexture_tjvyk")
}],
"loop": true,
"loop": 1,
"name": &"fall",
"speed": 5.0
}, {
@@ -222,7 +215,7 @@ animations = [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_vecdo")
}],
"loop": true,
"loop": 1,
"name": &"fall_left",
"speed": 5.0
}, {
@@ -230,7 +223,7 @@ animations = [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_qly8p")
}],
"loop": true,
"loop": 1,
"name": &"fall_right",
"speed": 5.0
}, {
@@ -244,7 +237,7 @@ animations = [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_ijx3p")
}],
"loop": true,
"loop": 1,
"name": &"idle",
"speed": 5.0
}, {
@@ -252,7 +245,7 @@ animations = [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_klrad")
}],
"loop": true,
"loop": 1,
"name": &"jump",
"speed": 5.0
}, {
@@ -260,7 +253,7 @@ animations = [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_rjy0i")
}],
"loop": true,
"loop": 1,
"name": &"jump_left",
"speed": 5.0
}, {
@@ -268,7 +261,7 @@ animations = [{
"duration": 5.0,
"texture": SubResource("AtlasTexture_ps2ar")
}],
"loop": true,
"loop": 1,
"name": &"jump_right",
"speed": 5.0
}, {
@@ -285,7 +278,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_soo8x")
}],
"loop": true,
"loop": 1,
"name": &"look_around",
"speed": 5.0
}, {
@@ -305,7 +298,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_vbirv")
}],
"loop": false,
"loop": 0,
"name": &"look_around_1",
"speed": 5.0
}, {
@@ -325,7 +318,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_hrljr")
}],
"loop": false,
"loop": 0,
"name": &"look_around_2",
"speed": 5.0
}, {
@@ -354,7 +347,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_x6npu")
}],
"loop": true,
"loop": 1,
"name": &"walk_left",
"speed": 10.0
}, {
@@ -383,13 +376,21 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_0xs27")
}],
"loop": true,
"loop": 1,
"name": &"walk_right",
"speed": 10.0
}]
[node name="CultistSprite" type="AnimatedSprite2D" unique_id=351120861]
material = SubResource("ShaderMaterial_vecdo")
[node name="CultistSprite" type="Sprite2D" unique_id=1870874123]
material = ExtResource("1_1pedr")
texture = SubResource("ViewportTexture_bhunq")
script = ExtResource("2_ew6gn")
[node name="SubViewport" type="SubViewport" parent="." unique_id=1722886587]
transparent_bg = true
size = Vector2i(32, 32)
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="SubViewport" unique_id=1233349440]
position = Vector2(16, 16)
sprite_frames = SubResource("SpriteFrames_2wrno")
animation = &"idle"
script = ExtResource("3_ef0vi")
-2
View File
@@ -1,2 +0,0 @@
class_name GrayCultist
extends AbstractCultist
@@ -1 +0,0 @@
uid://cern5veiqkrkc
-38
View File
@@ -1,38 +0,0 @@
[gd_scene format=3 uid="uid://cb0w6mt8g4mer"]
[ext_resource type="PackedScene" uid="uid://bx0luh4vdob3q" path="res://game/characters/enemies/abstract_cultist.tscn" id="1_q3s46"]
[ext_resource type="Script" uid="uid://cern5veiqkrkc" path="res://game/characters/enemies/gray_cultist.gd" id="2_olede"]
[ext_resource type="Material" uid="uid://dbkn3k0batj5w" path="res://game/materials/enemy_gray.tres" id="3_ho47d"]
[sub_resource type="ViewportTexture" id="ViewportTexture_b3gyl"]
viewport_path = NodePath("SubViewport")
[node name="GrayCultist" unique_id=139812221 instance=ExtResource("1_q3s46")]
collision_layer = 16
collision_mask = 35
script = ExtResource("2_olede")
[node name="CultistSprite" parent="." index="0" unique_id=797412888]
material = ExtResource("3_ho47d")
texture = SubResource("ViewportTexture_b3gyl")
[node name="LeftWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="0" unique_id=521416854]
collision_mask = 35
[node name="RightWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="1" unique_id=1457669135]
collision_mask = 35
[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="0" unique_id=947570027]
collision_mask = 171
[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="1" unique_id=1559118218]
collision_mask = 171
[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="0" unique_id=1491085518]
collision_mask = 171
[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="1" unique_id=1377654831]
collision_mask = 171
[node name="KillingArea" parent="." index="7" unique_id=1891922549]
collision_mask = 136
@@ -6,7 +6,7 @@ const DIRECTION_LEFT = -1
const DIRECTION_RIGHT = 1
@export var cultist: AbstractCultist
@export var cultist: Cultist
func _get_colliding_player(ray_cast: RayCast2D) -> Player:
@@ -2,4 +2,4 @@ class_name CultistStateMachine
extends StateMachine
@export var cultist: AbstractCultist
@export var cultist: Cultist
-2
View File
@@ -1,2 +0,0 @@
class_name WhiteCultist
extends AbstractColorCultist
@@ -1 +0,0 @@
uid://dmcpkytgiuedi
@@ -1,40 +0,0 @@
[gd_scene format=3 uid="uid://bv2gahb4wxgb1"]
[ext_resource type="PackedScene" uid="uid://d37eyum03h83i" path="res://game/characters/enemies/abstract_color_cultist.tscn" id="1_3yi7g"]
[ext_resource type="Script" uid="uid://dmcpkytgiuedi" path="res://game/characters/enemies/white_cultist.gd" id="2_c7pdf"]
[ext_resource type="Material" uid="uid://ci7xuso12af5" path="res://game/materials/enemy_white.tres" id="3_36f86"]
[sub_resource type="ViewportTexture" id="ViewportTexture_fb5t4"]
viewport_path = NodePath("SubViewport")
[node name="WhiteEnemy" unique_id=486389199 instance=ExtResource("1_3yi7g")]
collision_layer = 64
collision_mask = 33
script = ExtResource("2_c7pdf")
[node name="CultistSprite" parent="." index="0" unique_id=797412888]
material = ExtResource("3_36f86")
texture = SubResource("ViewportTexture_fb5t4")
[node name="LeftWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="0" unique_id=521416854]
collision_mask = 33
[node name="RightWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="1" unique_id=1457669135]
collision_mask = 33
[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="0" unique_id=947570027]
target_position = Vector2(-32, 0)
collision_mask = 161
[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="1" unique_id=1559118218]
target_position = Vector2(32, 0)
collision_mask = 161
[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="0" unique_id=1491085518]
collision_mask = 161
[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="1" unique_id=1377654831]
collision_mask = 161
[node name="KillingArea" parent="." index="8" unique_id=1891922549]
collision_mask = 128