From 3e73fe8e1ffc68540f5feba1c58c434abe9368fe Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Thu, 8 Jan 2026 17:25:53 +0300 Subject: [PATCH] Added enemy chasing --- game/characters/abstract_enemy.gd | 243 ++++++++++++++++++++++------ game/characters/abstract_enemy.tscn | 240 +++++++++++++++++++-------- game/characters/black_enemy.tscn | 21 +++ game/characters/gray_enemy.tscn | 20 ++- game/characters/player.gd | 2 +- game/characters/player.tscn | 6 +- game/characters/white_enemy.tscn | 22 ++- images/characters/cultist.png | 4 +- 8 files changed, 433 insertions(+), 125 deletions(-) diff --git a/game/characters/abstract_enemy.gd b/game/characters/abstract_enemy.gd index 32822e2..8bdbfd6 100644 --- a/game/characters/abstract_enemy.gd +++ b/game/characters/abstract_enemy.gd @@ -2,6 +2,27 @@ class_name AbstractEnemy extends CharacterBody2D +enum Type { + Standing, + Walking, + Random, +} + +enum Facing { + Front, + Rear, +} + +enum State { + Idle, + WalkLeft, + WalkRight, + LookAround, + ChasingLeft, + ChasingRight, +} + + const ANIMATION_FALL_DOWN = "fall_down" const ANIMATION_FALL_DOWN_LEFT = "fall_down_left" const ANIMATION_FALL_DOWN_RIGHT = "fall_down_right" @@ -16,102 +37,192 @@ const ANIMATION_LOOK_AROUND_REAR_1 = "look_around_rear_1" const ANIMATION_LOOK_AROUND_REAR_2 = "look_around_rear_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 = [ +const LOOK_AROUND_FRONT_ANIMATIONS : Array[String] = [ ANIMATION_LOOK_AROUND_FRONT_1, ANIMATION_LOOK_AROUND_FRONT_2, ] -const LOOK_AROUND_REAR_ANIMATIONS = [ +const LOOK_AROUND_REAR_ANIMATIONS : Array[String] = [ ANIMATION_LOOK_AROUND_REAR_1, ANIMATION_LOOK_AROUND_REAR_2, ] -const MAX_SPEED = 165 +const MAX_WALK_SPEED = 85 +const MAX_CHASE_SPEED = 170 const ACCELERATION = 600.0 const LOOK_AROUND_CHANCE = 25 +const WALK_CHANCE = 25 + +const DIRECTION_LEFT = -1 +const DIRECTION_RIGHT = 1 -enum Type { - Front, - Rear, -} - - -enum State { - Idle, - LookAround, - Chasing, -} - - -@export var type : Type = Type.Front -@export var state : State = State.Idle +@export var type : Type = Type.Standing +@export var facing : Facing = Facing.Front +@export var initial_state : State = State.Idle var _target_x := 0.0 +var _target_found := false +@onready var _state : State = initial_state: + set = _set_state + @onready var sprite : AnimatedSprite2D = $AnimatedSprite2D +@onready var left_wall_ray : RayCast2D = $%LeftWallRay +@onready var right_wall_ray : RayCast2D = $%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 + func _physics_process(delta: float) -> void: if not is_on_floor(): velocity += get_gravity() * delta - if state == State.Chasing: - if is_equal_approx(position.x, _target_x): - state = State.LookAround - else: - var direction := signf(_target_x - position.x) - velocity.x = move_toward(velocity.x, direction * MAX_SPEED, ACCELERATION * delta) + match _state: + State.ChasingLeft: + _process_player_ray(left_player_distant_ray) + if position.x < _target_x: + _state = State.LookAround + else: + _update_x_velocity(DIRECTION_LEFT, MAX_CHASE_SPEED, delta) + _check_wall_collision_and_switch_state(DIRECTION_LEFT) + State.ChasingRight: + _process_player_ray(right_player_distant_ray) + if position.x > _target_x: + _state = State.LookAround + else: + _update_x_velocity(DIRECTION_RIGHT, MAX_CHASE_SPEED, delta) + _check_wall_collision_and_switch_state(DIRECTION_RIGHT) + 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) + 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) + State.LookAround: + 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() +func _set_state(value: State) -> void: + _state = value + + left_player_close_ray.process_mode = Node.PROCESS_MODE_DISABLED + right_player_close_ray.process_mode = Node.PROCESS_MODE_DISABLED + left_player_distant_ray.process_mode = Node.PROCESS_MODE_DISABLED + right_player_distant_ray.process_mode = Node.PROCESS_MODE_DISABLED + + match _state: + State.ChasingLeft, State.WalkLeft: + left_player_distant_ray.process_mode = Node.PROCESS_MODE_INHERIT + State.ChasingRight, State.WalkRight: + left_player_distant_ray.process_mode = Node.PROCESS_MODE_INHERIT + State.LookAround: + left_player_close_ray.process_mode = Node.PROCESS_MODE_INHERIT + right_player_distant_ray.process_mode = Node.PROCESS_MODE_INHERIT + + +func _process_player_ray(ray: RayCast2D) -> bool: + if ray.is_colliding(): + var collider := ray.get_collider() + if collider is Player: + _target_x = collider.position.x + return true + return false + + +func _process_player_rays(rays: Array[RayCast2D]) -> bool: + for ray in rays: + if _process_player_ray(ray): + return true + return false + + +func _update_x_velocity(direction: int, max_speed: float, delta: float) -> void: + velocity.x = move_toward(velocity.x, direction * max_speed, ACCELERATION * delta) + + +func _check_wall_collision_and_switch_state(direction: int) -> void: + var this_wall_ray := _get_wall_ray(direction) + var other_wall_ray := _get_wall_ray(-direction) + + if this_wall_ray.is_colliding(): + if other_wall_ray.is_colliding(): + _state = State.LookAround + else: + match _state: + State.WalkLeft: + _state = State.WalkRight + State.WalkRight: + _state = State.WalkLeft + State.ChasingLeft, State.ChasingRight: + _state = State.LookAround + + +func _get_wall_ray(direction: int) -> RayCast2D: + if direction < 0: + return left_wall_ray + else: + return right_wall_ray + + func _update_animation() -> void: if is_zero_approx(velocity.y): - match state: + match _state: + State.WalkLeft: + _play_animation(ANIMATION_WALK_LEFT) + State.WalkRight: + _play_animation(ANIMATION_WALK_RIGHT) + State.ChasingLeft: + _play_animation(ANIMATION_CHASE_LEFT) + State.ChasingRight: + _play_animation(ANIMATION_CHASE_RIGHT) State.Idle: _play_idle_animation() State.LookAround: _play_look_around_animation() - State.Chasing: - _play_chasing_animation_animation() else: _play_fall_animation() func _play_idle_animation() -> void: - match type: - Type.Front: + match facing: + Facing.Front: _play_animation(ANIMATION_IDLE_FRONT) - Type.Rear: + Facing.Rear: _play_animation(ANIMATION_IDLE_REAR) func _play_look_around_animation() -> void: - if _is_current_animation_look_around: return + if _is_current_animation_look_around(): return - match type: - Type.Front: + match facing: + Facing.Front: var animation := _get_random_animation(LOOK_AROUND_FRONT_ANIMATIONS) _play_animation(animation) - Type.Rear: + Facing.Rear: var animation := _get_random_animation(LOOK_AROUND_REAR_ANIMATIONS) _play_animation(animation) -func _play_chasing_animation_animation() -> void: - if is_zero_approx(velocity.x): - pass - elif velocity.x < 0: - _play_animation(ANIMATION_WALK_LEFT) - else: - _play_animation(ANIMATION_WALK_RIGHT) - - func _play_fall_animation() -> void: if is_zero_approx(velocity.x): var animation := ANIMATION_FALL_UP if velocity.y < 0 else ANIMATION_FALL_DOWN @@ -141,10 +252,50 @@ func _play_animation(animation: String) -> void: sprite.play(animation) +func _set_walking_state() -> void: + var is_left_colliding := left_wall_ray.is_colliding() + var is_right_colliding := right_wall_ray.is_colliding() + + if is_left_colliding and is_right_colliding: + _state = State.Idle + elif not is_left_colliding and not is_right_colliding: + _state = State.WalkLeft if randi_range(1, 2) == 1 else State.WalkRight + elif not is_left_colliding: + _state = State.WalkLeft + else: + _state = State.WalkRight + + +func _set_chase_state() -> void: + if _target_x < position.x: + _state = State.ChasingLeft + else: + _state = State.ChasingRight + + +func _is_walking_state() -> bool: + return _state == State.WalkLeft or _state == State.WalkRight + + func _on_animation_finished() -> void: - state = State.Idle + if _target_found: + _set_chase_state() + _target_found = false + return + + match type: + Type.Standing: + _state = State.Idle + Type.Walking: + _set_walking_state() + Type.Random: + if randi_range(1, 100) <= WALK_CHANCE: + _set_walking_state() + else: + _state = State.Idle func _on_animation_looped() -> void: - if state == State.Idle and randi_range(1, 100) <= LOOK_AROUND_CHANCE: - state = State.LookAround + if _state == State.Idle or (type == Type.Random and _is_walking_state()): + if randi_range(1, 100) <= LOOK_AROUND_CHANCE: + _state = State.LookAround diff --git a/game/characters/abstract_enemy.tscn b/game/characters/abstract_enemy.tscn index f784fc4..4383a94 100644 --- a/game/characters/abstract_enemy.tscn +++ b/game/characters/abstract_enemy.tscn @@ -15,6 +15,70 @@ shader_parameter/speed = 5.0 shader_parameter/intensity = 1.0 shader_parameter/scale = 20.0 +[sub_resource type="AtlasTexture" id="AtlasTexture_l58xb"] +atlas = ExtResource("2_mocsw") +region = Rect2(0, 64, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_jrclg"] +atlas = ExtResource("2_mocsw") +region = Rect2(32, 64, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wwwee"] +atlas = ExtResource("2_mocsw") +region = Rect2(64, 64, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_law7y"] +atlas = ExtResource("2_mocsw") +region = Rect2(96, 64, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_hme24"] +atlas = ExtResource("2_mocsw") +region = Rect2(128, 64, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qawtf"] +atlas = ExtResource("2_mocsw") +region = Rect2(160, 64, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_srxh4"] +atlas = ExtResource("2_mocsw") +region = Rect2(192, 64, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_x6npu"] +atlas = ExtResource("2_mocsw") +region = Rect2(224, 64, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_xavx3"] +atlas = ExtResource("2_mocsw") +region = Rect2(0, 32, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8t4m8"] +atlas = ExtResource("2_mocsw") +region = Rect2(32, 32, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_3seah"] +atlas = ExtResource("2_mocsw") +region = Rect2(64, 32, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_koyeg"] +atlas = ExtResource("2_mocsw") +region = Rect2(96, 32, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_uw3v1"] +atlas = ExtResource("2_mocsw") +region = Rect2(128, 32, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_265lf"] +atlas = ExtResource("2_mocsw") +region = Rect2(160, 32, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_tav7c"] +atlas = ExtResource("2_mocsw") +region = Rect2(192, 32, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_0xs27"] +atlas = ExtResource("2_mocsw") +region = Rect2(224, 32, 32, 32) + [sub_resource type="AtlasTexture" id="AtlasTexture_tjvyk"] atlas = ExtResource("2_mocsw") region = Rect2(128, 96, 32, 32) @@ -103,74 +167,68 @@ region = Rect2(128, 0, 32, 32) atlas = ExtResource("2_mocsw") region = Rect2(192, 0, 32, 32) -[sub_resource type="AtlasTexture" id="AtlasTexture_l58xb"] -atlas = ExtResource("2_mocsw") -region = Rect2(0, 64, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_jrclg"] -atlas = ExtResource("2_mocsw") -region = Rect2(32, 64, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_wwwee"] -atlas = ExtResource("2_mocsw") -region = Rect2(64, 64, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_law7y"] -atlas = ExtResource("2_mocsw") -region = Rect2(96, 64, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_hme24"] -atlas = ExtResource("2_mocsw") -region = Rect2(128, 64, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_qawtf"] -atlas = ExtResource("2_mocsw") -region = Rect2(160, 64, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_srxh4"] -atlas = ExtResource("2_mocsw") -region = Rect2(192, 64, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_x6npu"] -atlas = ExtResource("2_mocsw") -region = Rect2(224, 64, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_xavx3"] -atlas = ExtResource("2_mocsw") -region = Rect2(0, 32, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_8t4m8"] -atlas = ExtResource("2_mocsw") -region = Rect2(32, 32, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_3seah"] -atlas = ExtResource("2_mocsw") -region = Rect2(64, 32, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_koyeg"] -atlas = ExtResource("2_mocsw") -region = Rect2(96, 32, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_uw3v1"] -atlas = ExtResource("2_mocsw") -region = Rect2(128, 32, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_265lf"] -atlas = ExtResource("2_mocsw") -region = Rect2(160, 32, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_tav7c"] -atlas = ExtResource("2_mocsw") -region = Rect2(192, 32, 32, 32) - -[sub_resource type="AtlasTexture" id="AtlasTexture_0xs27"] -atlas = ExtResource("2_mocsw") -region = Rect2(224, 32, 32, 32) - [sub_resource type="SpriteFrames" id="SpriteFrames_2wrno"] animations = [{ "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_l58xb") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_jrclg") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_wwwee") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_law7y") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_hme24") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_qawtf") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_srxh4") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_x6npu") +}], +"loop": true, +"name": &"chase_left", +"speed": 20.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_xavx3") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8t4m8") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_3seah") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_koyeg") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_uw3v1") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_265lf") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_tav7c") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_0xs27") +}], +"loop": true, +"name": &"chase_right", +"speed": 20.0 +}, { +"frames": [{ +"duration": 10.0, "texture": SubResource("AtlasTexture_tjvyk") }], "loop": true, @@ -178,7 +236,7 @@ animations = [{ "speed": 5.0 }, { "frames": [{ -"duration": 1.0, +"duration": 5.0, "texture": SubResource("AtlasTexture_vecdo") }], "loop": true, @@ -186,7 +244,7 @@ animations = [{ "speed": 5.0 }, { "frames": [{ -"duration": 1.0, +"duration": 5.0, "texture": SubResource("AtlasTexture_qly8p") }], "loop": true, @@ -194,7 +252,7 @@ animations = [{ "speed": 5.0 }, { "frames": [{ -"duration": 1.0, +"duration": 5.0, "texture": SubResource("AtlasTexture_klrad") }], "loop": true, @@ -202,7 +260,7 @@ animations = [{ "speed": 5.0 }, { "frames": [{ -"duration": 1.0, +"duration": 5.0, "texture": SubResource("AtlasTexture_rjy0i") }], "loop": true, @@ -210,7 +268,7 @@ animations = [{ "speed": 5.0 }, { "frames": [{ -"duration": 1.0, +"duration": 5.0, "texture": SubResource("AtlasTexture_ps2ar") }], "loop": true, @@ -218,22 +276,28 @@ animations = [{ "speed": 5.0 }, { "frames": [{ -"duration": 9.0, +"duration": 4.0, "texture": SubResource("AtlasTexture_ijx3p") }, { "duration": 1.0, "texture": SubResource("AtlasTexture_nm8xp") +}, { +"duration": 5.0, +"texture": SubResource("AtlasTexture_ijx3p") }], "loop": true, "name": &"idle_front", "speed": 5.0 }, { "frames": [{ -"duration": 9.0, +"duration": 4.0, "texture": SubResource("AtlasTexture_mocsw") }, { "duration": 1.0, "texture": SubResource("AtlasTexture_y256a") +}, { +"duration": 5.0, +"texture": SubResource("AtlasTexture_mocsw") }], "loop": true, "name": &"idle_rear", @@ -373,5 +437,39 @@ shape = SubResource("CapsuleShape2D_mocsw") [node name="PlayerKiller" parent="." instance=ExtResource("4_vecdo")] +[node name="WallCheck" type="Node2D" parent="."] + +[node name="LeftWallRay" type="RayCast2D" parent="WallCheck"] +unique_name_in_owner = true +target_position = Vector2(-16, 0) + +[node name="RightWallRay" type="RayCast2D" parent="WallCheck"] +unique_name_in_owner = true +target_position = Vector2(16, 0) + +[node name="PlayerCloseCheck" type="Node2D" parent="."] + +[node name="LeftPlayerCloseRay" type="RayCast2D" parent="PlayerCloseCheck"] +unique_name_in_owner = true +target_position = Vector2(-48, 0) +collision_mask = 0 + +[node name="RightPlayerCloseRay" type="RayCast2D" parent="PlayerCloseCheck"] +unique_name_in_owner = true +target_position = Vector2(48, 0) +collision_mask = 0 + +[node name="PlayerDistantCheck" type="Node2D" parent="."] + +[node name="LeftPlayerDistantRay" type="RayCast2D" parent="PlayerDistantCheck"] +unique_name_in_owner = true +target_position = Vector2(-320, 0) +collision_mask = 0 + +[node name="RightPlayerDistantRay" type="RayCast2D" parent="PlayerDistantCheck"] +unique_name_in_owner = true +target_position = Vector2(320, 0) +collision_mask = 0 + [connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"] [connection signal="animation_looped" from="AnimatedSprite2D" to="." method="_on_animation_looped"] diff --git a/game/characters/black_enemy.tscn b/game/characters/black_enemy.tscn index 2371e07..8674d9e 100644 --- a/game/characters/black_enemy.tscn +++ b/game/characters/black_enemy.tscn @@ -17,6 +17,7 @@ shader_parameter/scale = 20.0 [node name="BlackEnemy" instance=ExtResource("1_gj2ks")] collision_layer = 4 +collision_mask = 3 script = ExtResource("2_332ds") [node name="AnimatedSprite2D" parent="." index="0"] @@ -24,3 +25,23 @@ material = SubResource("ShaderMaterial_3jy5n") [node name="CollisionSwitcher" parent="." index="2"] initial_state = 0 + +[node name="LeftWallRay" parent="WallCheck" index="0"] +collision_mask = 3 + +[node name="RightWallRay" parent="WallCheck" index="1"] +collision_mask = 3 + +[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" index="0"] +target_position = Vector2(-32, 0) +collision_mask = 8 + +[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" index="1"] +target_position = Vector2(32, 0) +collision_mask = 8 + +[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" index="0"] +collision_mask = 8 + +[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" index="1"] +collision_mask = 8 diff --git a/game/characters/gray_enemy.tscn b/game/characters/gray_enemy.tscn index 1489746..e450975 100644 --- a/game/characters/gray_enemy.tscn +++ b/game/characters/gray_enemy.tscn @@ -16,8 +16,26 @@ shader_parameter/scale = 20.0 [node name="GrayEnemy" instance=ExtResource("1_q3s46")] collision_layer = 16 -collision_mask = 137 +collision_mask = 35 script = ExtResource("2_olede") [node name="AnimatedSprite2D" parent="." index="0"] material = SubResource("ShaderMaterial_hsdrn") + +[node name="LeftWallRay" parent="WallCheck" index="0"] +collision_mask = 35 + +[node name="RightWallRay" parent="WallCheck" index="1"] +collision_mask = 35 + +[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" index="0"] +collision_mask = 136 + +[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" index="1"] +collision_mask = 136 + +[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" index="0"] +collision_mask = 136 + +[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" index="1"] +collision_mask = 136 diff --git a/game/characters/player.gd b/game/characters/player.gd index e90edc2..63fc40e 100644 --- a/game/characters/player.gd +++ b/game/characters/player.gd @@ -71,7 +71,7 @@ func _physics_process(delta: float) -> void: func _input(event: InputEvent) -> void: - if event.is_action_pressed("switch_color"): + if event.is_action_pressed("switch_color") and _is_alive: collision_switcher.switch_color(switch_time) diff --git a/game/characters/player.tscn b/game/characters/player.tscn index f26b90b..a525f70 100644 --- a/game/characters/player.tscn +++ b/game/characters/player.tscn @@ -367,7 +367,7 @@ animations = [{ }], "loop": true, "name": &"walk_left", -"speed": 10.0 +"speed": 20.0 }, { "frames": [{ "duration": 1.0, @@ -396,7 +396,7 @@ animations = [{ }], "loop": true, "name": &"walk_right", -"speed": 10.0 +"speed": 20.0 }] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"] @@ -410,7 +410,7 @@ script = ExtResource("1_xln5q") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] material = SubResource("ShaderMaterial_i05k5") sprite_frames = SubResource("SpriteFrames_v8w1g") -animation = &"walk_right" +animation = &"idle" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, 1) diff --git a/game/characters/white_enemy.tscn b/game/characters/white_enemy.tscn index 22cdd03..7031940 100644 --- a/game/characters/white_enemy.tscn +++ b/game/characters/white_enemy.tscn @@ -17,8 +17,28 @@ shader_parameter/scale = 20.0 [node name="WhiteEnemy" instance=ExtResource("1_3yi7g")] collision_layer = 64 -collision_mask = 129 +collision_mask = 33 script = ExtResource("2_c7pdf") [node name="AnimatedSprite2D" parent="." index="0"] material = SubResource("ShaderMaterial_gfhm1") + +[node name="LeftWallRay" parent="WallCheck" index="0"] +collision_mask = 33 + +[node name="RightWallRay" parent="WallCheck" index="1"] +collision_mask = 33 + +[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" index="0"] +target_position = Vector2(-32, 0) +collision_mask = 128 + +[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" index="1"] +target_position = Vector2(32, 0) +collision_mask = 128 + +[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" index="0"] +collision_mask = 128 + +[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" index="1"] +collision_mask = 128 diff --git a/images/characters/cultist.png b/images/characters/cultist.png index 78e9eab..623d976 100644 --- a/images/characters/cultist.png +++ b/images/characters/cultist.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:feff984eeb878a882aacc233e0ffa4886dbda3db74f6eaf77a8d22bbceff7cc5 -size 1427 +oid sha256:ad8c7715643872b1f1f49a16a1dc9f7b19592e332da7a82edf70501f184a2e4e +size 1424