Изменена логика доспеха
This commit is contained in:
parent
429fe9b62f
commit
1fe08a596d
4 changed files with 133 additions and 43 deletions
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://bpusphyhhg074"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://bpusphyhhg074"]
|
||||
|
||||
[ext_resource type="SpriteFrames" uid="uid://cw4pv1qucngxu" path="res://sprites/enemies/armor/living_armor.tres" id="1_j445m"]
|
||||
[ext_resource type="Script" path="res://scripts/enemies/LivingArmor.cs" id="1_ofbsx"]
|
||||
|
@ -7,10 +7,17 @@
|
|||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_d1ojb"]
|
||||
size = Vector2(15, 15)
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ex1co"]
|
||||
radius = 150.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_62y1x"]
|
||||
radius = 15.0
|
||||
|
||||
[node name="LivingArmor" type="CharacterBody2D"]
|
||||
collision_layer = 5
|
||||
collision_mask = 5
|
||||
script = ExtResource("1_ofbsx")
|
||||
MovingSpeed = 35.0
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
sprite_frames = ExtResource("1_j445m")
|
||||
|
@ -28,5 +35,21 @@ polygon = PackedVector2Array(-7, -4, -7, 15, 8, 15, 8, -4, 5, -11, -4, -11)
|
|||
position = Vector2(0.5, 7.5)
|
||||
shape = SubResource("RectangleShape2D_d1ojb")
|
||||
|
||||
[node name="AreaOfSight" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="AreaOfSight"]
|
||||
shape = SubResource("CircleShape2D_ex1co")
|
||||
|
||||
[node name="PlayerCollision" type="Area2D" parent="."]
|
||||
monitorable = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerCollision"]
|
||||
position = Vector2(1, 8)
|
||||
shape = SubResource("CircleShape2D_62y1x")
|
||||
|
||||
[connection signal="area_entered" from="LightSense" to="." method="_OnLightEntered"]
|
||||
[connection signal="area_exited" from="LightSense" to="." method="_OnLightExited"]
|
||||
[connection signal="body_entered" from="AreaOfSight" to="." method="_OnBodyEntered"]
|
||||
[connection signal="body_exited" from="AreaOfSight" to="." method="_OnBodyExited"]
|
||||
[connection signal="body_entered" from="PlayerCollision" to="." method="_OnPlayerCollision"]
|
||||
[connection signal="body_exited" from="PlayerCollision" to="." method="_OnPlayerCollisionExited"]
|
||||
|
|
|
@ -32,6 +32,7 @@ position = Vector2(1, 8)
|
|||
shape = SubResource("RectangleShape2D_svj4b")
|
||||
|
||||
[node name="PlayerCollision" type="Area2D" parent="."]
|
||||
monitorable = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerCollision"]
|
||||
position = Vector2(1, 8)
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://bj1ixwjdpnooo" path="res://prefabs/entities/pressure_plate.tscn" id="12_ynt5e"]
|
||||
[ext_resource type="PackedScene" uid="uid://dqx43vr727ft8" path="res://prefabs/entities/spikes.tscn" id="13_w1hk1"]
|
||||
[ext_resource type="Script" path="res://scripts/DeathScreen.cs" id="15_12mhe"]
|
||||
[ext_resource type="PackedScene" uid="uid://bmyjqerhno5vi" path="res://prefabs/enemies/wretched.tscn" id="16_wjfbi"]
|
||||
[ext_resource type="PackedScene" uid="uid://bmyjqerhno5vi" path="res://prefabs/enemies/wretched.tscn" id="16_ejflu"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_o5byr"]
|
||||
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0]
|
||||
|
@ -27,7 +27,7 @@ light_mode = 2
|
|||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_m680d"]
|
||||
shader = ExtResource("5_64d71")
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_pqovb"]
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_1dtfl"]
|
||||
viewport_path = NodePath("FlashlightViewport")
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_prnh4"]
|
||||
|
@ -123,7 +123,7 @@ CameraBounds = Vector2(30, 20)
|
|||
[node name="PointLight2D" type="PointLight2D" parent="PlayerCamera" node_paths=PackedStringArray("LightViewport")]
|
||||
blend_mode = 2
|
||||
range_item_cull_mask = 2
|
||||
texture = SubResource("ViewportTexture_pqovb")
|
||||
texture = SubResource("ViewportTexture_1dtfl")
|
||||
script = ExtResource("6_slohe")
|
||||
LightViewport = NodePath("../../FlashlightViewport")
|
||||
|
||||
|
@ -196,18 +196,6 @@ position = Vector2(116, -76)
|
|||
[node name="LivingArmor" parent="." instance=ExtResource("11_x3ep3")]
|
||||
position = Vector2(-70, -67)
|
||||
|
||||
[node name="LivingArmor2" parent="." instance=ExtResource("11_x3ep3")]
|
||||
position = Vector2(-86, -51)
|
||||
Facing = 2
|
||||
|
||||
[node name="LivingArmor3" parent="." instance=ExtResource("11_x3ep3")]
|
||||
position = Vector2(-54, -50)
|
||||
Facing = 0
|
||||
|
||||
[node name="LivingArmor4" parent="." instance=ExtResource("11_x3ep3")]
|
||||
position = Vector2(-70, -36)
|
||||
Facing = 1
|
||||
|
||||
[node name="pressure_plate" parent="." instance=ExtResource("12_ynt5e")]
|
||||
position = Vector2(31, 51)
|
||||
|
||||
|
@ -228,19 +216,10 @@ Enabled = true
|
|||
SpikesTimeout = 0.5
|
||||
StartOffset = 0.5
|
||||
|
||||
[node name="Wretched" parent="." instance=ExtResource("16_wjfbi")]
|
||||
position = Vector2(-84, 12)
|
||||
[node name="Wretched" parent="." instance=ExtResource("16_ejflu")]
|
||||
position = Vector2(-120, 42)
|
||||
|
||||
[node name="Wretched2" parent="." instance=ExtResource("16_wjfbi")]
|
||||
position = Vector2(-108, 30)
|
||||
Facing = 2
|
||||
|
||||
[node name="Wretched3" parent="." instance=ExtResource("16_wjfbi")]
|
||||
position = Vector2(-64, 29)
|
||||
Facing = 0
|
||||
|
||||
[node name="Wretched4" parent="." instance=ExtResource("16_wjfbi")]
|
||||
position = Vector2(-85, 51)
|
||||
Facing = 1
|
||||
[node name="Wretched2" parent="." instance=ExtResource("16_ejflu")]
|
||||
position = Vector2(-139, -39)
|
||||
|
||||
[connection signal="timeout" from="CanvasLayer/DeathScreen/Timer" to="CanvasLayer/DeathScreen" method="Timeout"]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class LivingArmor : CharacterBody2D
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ public partial class LivingArmor : CharacterBody2D
|
|||
Moving,
|
||||
Attack
|
||||
}
|
||||
|
||||
|
||||
public enum SideFace
|
||||
{
|
||||
Left,
|
||||
|
@ -17,10 +18,10 @@ public partial class LivingArmor : CharacterBody2D
|
|||
Right,
|
||||
Down
|
||||
}
|
||||
|
||||
|
||||
[Export] public SideFace Facing = SideFace.Down;
|
||||
[Export] public float MovingSpeed = 16f;
|
||||
|
||||
|
||||
public State CurrentState
|
||||
{
|
||||
get => _state;
|
||||
|
@ -46,7 +47,11 @@ public partial class LivingArmor : CharacterBody2D
|
|||
private float _timeSinceState;
|
||||
private AnimatedSprite2D _sprite;
|
||||
private bool _isLitUp;
|
||||
|
||||
//private readonly List<WeakRef> _bodiesInSight = new List<WeakRef>();
|
||||
private readonly List<Node2D> _bodiesInSight = new List<Node2D>();
|
||||
private readonly List<Node2D> _bodiesNearBy = new List<Node2D>();
|
||||
private Node2D _target = null;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
|
@ -66,6 +71,7 @@ public partial class LivingArmor : CharacterBody2D
|
|||
animationName = "down_walk";
|
||||
break;
|
||||
}
|
||||
|
||||
_sprite.Play(animationName);
|
||||
_sprite.Stop();
|
||||
}
|
||||
|
@ -87,7 +93,42 @@ public partial class LivingArmor : CharacterBody2D
|
|||
break;
|
||||
|
||||
case State.Moving:
|
||||
var direction = (Player.Instance.Position - Position).Normalized();
|
||||
foreach (var body in _bodiesNearBy)
|
||||
{
|
||||
switch (body)
|
||||
{
|
||||
case Wretched wretched:
|
||||
wretched.Kill(this);
|
||||
break;
|
||||
case Player player:
|
||||
player.Kill(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
SearchTarget();
|
||||
switch (_target)
|
||||
{
|
||||
case Player player:
|
||||
if (!player.Alive)
|
||||
{
|
||||
_bodiesInSight.Remove(player);
|
||||
_target = null;
|
||||
}
|
||||
break;
|
||||
case Wretched wretched:
|
||||
if (!wretched.IsAlive)
|
||||
{
|
||||
_bodiesInSight.Remove(wretched);
|
||||
_target = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (_target is null)
|
||||
{
|
||||
_state = State.Waiting;
|
||||
return;
|
||||
}
|
||||
var direction = (_target.Position - Position).Normalized();
|
||||
Velocity = direction * MovingSpeed;
|
||||
|
||||
var animationName = "side_walk";
|
||||
|
@ -106,9 +147,39 @@ public partial class LivingArmor : CharacterBody2D
|
|||
//MoveAndCollide(direction);
|
||||
break;
|
||||
}
|
||||
|
||||
CheckIfLitUp();
|
||||
}
|
||||
|
||||
private void SearchTarget()
|
||||
{
|
||||
float targetDistance = -1;
|
||||
foreach (var body in _bodiesInSight)
|
||||
{
|
||||
var distance = (body.Position - Position).Length();
|
||||
GD.Print($"{body.Name}");
|
||||
switch (body)
|
||||
{
|
||||
case Wretched wretched:
|
||||
if (targetDistance < 0 || targetDistance > distance)
|
||||
{
|
||||
targetDistance = distance;
|
||||
_target = wretched;
|
||||
}
|
||||
break;
|
||||
case Player player:
|
||||
|
||||
if (_target is Wretched)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_target = player;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _OnLightEntered(Area2D area)
|
||||
{
|
||||
if (area.GetParentOrNull<GameCamera>() is null)
|
||||
|
@ -120,13 +191,7 @@ public partial class LivingArmor : CharacterBody2D
|
|||
|
||||
private void _OnPlayerCollision(Node2D body)
|
||||
{
|
||||
if (body is not Player player)
|
||||
return;
|
||||
|
||||
if (CurrentState is State.Waiting)
|
||||
return;
|
||||
|
||||
player.Kill(this);
|
||||
_bodiesNearBy.Add(body);
|
||||
}
|
||||
|
||||
private void _OnLightExited(Area2D area)
|
||||
|
@ -139,6 +204,7 @@ public partial class LivingArmor : CharacterBody2D
|
|||
|
||||
private void _OnPlayerCollisionExited(Node2D body)
|
||||
{
|
||||
_bodiesNearBy.Remove(body);
|
||||
}
|
||||
|
||||
void CheckIfLitUp()
|
||||
|
@ -148,10 +214,31 @@ public partial class LivingArmor : CharacterBody2D
|
|||
CurrentState = State.Waiting;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (CurrentState is State.Moving or State.Attack)
|
||||
return;
|
||||
|
||||
CurrentState = State.Moving;
|
||||
}
|
||||
|
||||
|
||||
private void _OnBodyEntered(Node2D body)
|
||||
{
|
||||
if (body is not Wretched and not Player)
|
||||
return;
|
||||
|
||||
_bodiesInSight.Add(body);
|
||||
}
|
||||
|
||||
|
||||
private void _OnBodyExited(Node2D body)
|
||||
{
|
||||
if (body is not Wretched and not Player)
|
||||
return;
|
||||
if (body == _target)
|
||||
{
|
||||
_target = null;
|
||||
}
|
||||
_bodiesInSight.Remove(body);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue