mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-18 17:03:48 +00:00
Damage actor handler
This commit is contained in:
parent
335f4d5430
commit
4fd31d7988
7 changed files with 100 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=14 format=3 uid="uid://bc054js8ep2b"]
|
[gd_scene load_steps=16 format=3 uid="uid://bc054js8ep2b"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Scripts/Components/Actors/Actor.cs" id="1_ugrra"]
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/Actor.cs" id="1_ugrra"]
|
||||||
[ext_resource type="SpriteFrames" uid="uid://ch2ll1on8im2p" path="res://Resources/Sprites/FairyGuard.tres" id="2_i2plx"]
|
[ext_resource type="SpriteFrames" uid="uid://ch2ll1on8im2p" path="res://Resources/Sprites/FairyGuard.tres" id="2_i2plx"]
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
[ext_resource type="Script" path="res://Scripts/Components/Actors/ActorResourceProvider.cs" id="9_fyr27"]
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/ActorResourceProvider.cs" id="9_fyr27"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cj63k0dmk7tl1" path="res://Scenes/Weapons/enemy_weapon_base.tscn" id="10_yktta"]
|
[ext_resource type="PackedScene" uid="uid://cj63k0dmk7tl1" path="res://Scenes/Weapons/enemy_weapon_base.tscn" id="10_yktta"]
|
||||||
[ext_resource type="Resource" uid="uid://cdfmedtgp2rcn" path="res://Resources/Weapons/EnemyWeapon.tres" id="11_kuimj"]
|
[ext_resource type="Resource" uid="uid://cdfmedtgp2rcn" path="res://Resources/Weapons/EnemyWeapon.tres" id="11_kuimj"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/DamageReceiverActorModule.cs" id="12_fu5g7"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_2b36v"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_2b36v"]
|
||||||
radius = 5.0
|
radius = 5.0
|
||||||
|
|
@ -18,6 +19,9 @@ radius = 5.0
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_sthwe"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_sthwe"]
|
||||||
radius = 85.0529
|
radius = 85.0529
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_0tkae"]
|
||||||
|
radius = 5.09902
|
||||||
|
|
||||||
[node name="ActorEnemyTest" type="CharacterBody2D"]
|
[node name="ActorEnemyTest" type="CharacterBody2D"]
|
||||||
collision_layer = 16
|
collision_layer = 16
|
||||||
collision_mask = 113
|
collision_mask = 113
|
||||||
|
|
@ -71,10 +75,24 @@ debug_path_custom_color = Color(1, 0, 0, 1)
|
||||||
[node name="HealthProvider" type="Node2D" parent="."]
|
[node name="HealthProvider" type="Node2D" parent="."]
|
||||||
script = ExtResource("9_fyr27")
|
script = ExtResource("9_fyr27")
|
||||||
ResourceName = "Health"
|
ResourceName = "Health"
|
||||||
|
MaxResource = 4.0
|
||||||
|
|
||||||
[node name="EnemyWeapon" parent="." instance=ExtResource("10_yktta")]
|
[node name="EnemyWeapon" parent="." instance=ExtResource("10_yktta")]
|
||||||
WeaponData = ExtResource("11_kuimj")
|
WeaponData = ExtResource("11_kuimj")
|
||||||
|
|
||||||
|
[node name="DamageReceiver" type="Node2D" parent="." node_paths=PackedStringArray("HealthProvider")]
|
||||||
|
script = ExtResource("12_fu5g7")
|
||||||
|
HealthProvider = NodePath("../HealthProvider")
|
||||||
|
BulletGroup = 2
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="DamageReceiver"]
|
||||||
|
collision_layer = 16
|
||||||
|
collision_mask = 8
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="DamageReceiver/Area2D"]
|
||||||
|
shape = SubResource("CircleShape2D_0tkae")
|
||||||
|
|
||||||
[connection signal="area_entered" from="PlayerDetection" to="PlayerDetection" method="_on_area_entered"]
|
[connection signal="area_entered" from="PlayerDetection" to="PlayerDetection" method="_on_area_entered"]
|
||||||
[connection signal="area_exited" from="PlayerDetection" to="PlayerDetection" method="_on_area_exited"]
|
[connection signal="area_exited" from="PlayerDetection" to="PlayerDetection" method="_on_area_exited"]
|
||||||
[connection signal="velocity_computed" from="NavigationAgent2D" to="NavigationMovementProvider" method="_on_navigation_agent_2d_velocity_computed"]
|
[connection signal="velocity_computed" from="NavigationAgent2D" to="NavigationMovementProvider" method="_on_navigation_agent_2d_velocity_computed"]
|
||||||
|
[connection signal="area_entered" from="DamageReceiver/Area2D" to="DamageReceiver" method="_on_damage_hitbox_area_entered"]
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ public partial class Actor : CharacterBody2D
|
||||||
|
|
||||||
private List<ActorModule> _modules = new();
|
private List<ActorModule> _modules = new();
|
||||||
|
|
||||||
|
public bool IsDestroyed { get; set; }
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = this.GetGameManager();
|
_gameManager = this.GetGameManager();
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ public partial class ActorFreeMovement : MovementHandler
|
||||||
set => _parent.MovementDirection = value;
|
set => _parent.MovementDirection = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsDestroyed => _parent.IsDestroyed;
|
||||||
|
|
||||||
public override void Init(Actor parent)
|
public override void Init(Actor parent)
|
||||||
{
|
{
|
||||||
base.Init(parent);
|
base.Init(parent);
|
||||||
|
|
@ -32,6 +34,8 @@ public partial class ActorFreeMovement : MovementHandler
|
||||||
|
|
||||||
public override void PhysicsUpdate(double delta)
|
public override void PhysicsUpdate(double delta)
|
||||||
{
|
{
|
||||||
|
if (IsDestroyed) return;
|
||||||
|
|
||||||
MovementDirection = AggregateInputProviders().Normalized();
|
MovementDirection = AggregateInputProviders().Normalized();
|
||||||
|
|
||||||
var aimingDirection = GetAimingDirection().Normalized();
|
var aimingDirection = GetAimingDirection().Normalized();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ public partial class AnimationHandler : ActorModule
|
||||||
|
|
||||||
protected Actor _parent;
|
protected Actor _parent;
|
||||||
|
|
||||||
|
public bool IsDestroyed => _parent.IsDestroyed;
|
||||||
|
|
||||||
public override void Init(Actor parent)
|
public override void Init(Actor parent)
|
||||||
{
|
{
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
|
|
@ -25,6 +27,8 @@ public partial class AnimationHandler : ActorModule
|
||||||
|
|
||||||
public override void Update(double delta)
|
public override void Update(double delta)
|
||||||
{
|
{
|
||||||
|
if (IsDestroyed) return;
|
||||||
|
|
||||||
var direction = _parent.FacingDirection; //GetSnappedDirection();
|
var direction = _parent.FacingDirection; //GetSnappedDirection();
|
||||||
|
|
||||||
if (_parent.Velocity.Length() > 0)
|
if (_parent.Velocity.Length() > 0)
|
||||||
|
|
@ -38,7 +42,6 @@ public partial class AnimationHandler : ActorModule
|
||||||
_animatedSprite.Play("walk_" + DirectionToString(direction));
|
_animatedSprite.Play("walk_" + DirectionToString(direction));
|
||||||
_animatedSprite.SpeedScale = 0;
|
_animatedSprite.SpeedScale = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PhysicsUpdate(double delta)
|
public override void PhysicsUpdate(double delta)
|
||||||
|
|
|
||||||
66
Scripts/Components/Actors/DamageReceiverActorModule.cs
Normal file
66
Scripts/Components/Actors/DamageReceiverActorModule.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Components.Actors;
|
||||||
|
|
||||||
|
public partial class DamageReceiverActorModule : ActorModule
|
||||||
|
{
|
||||||
|
protected Actor _actor;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public ActorResourceProvider HealthProvider { get; private set; }
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public bool Invulnerable { get; private set; } = false;
|
||||||
|
|
||||||
|
[Export] protected BulletOwner BulletGroup { get; set; } = BulletOwner.None;
|
||||||
|
|
||||||
|
public override void Init(Actor actor)
|
||||||
|
{
|
||||||
|
_actor = actor;
|
||||||
|
|
||||||
|
HealthProvider.ResourceDepleted += OnDeath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(double delta)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void PhysicsUpdate(double delta)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _on_damage_hitbox_area_entered(Area2D area)
|
||||||
|
{
|
||||||
|
if (_actor.IsDestroyed) return;
|
||||||
|
if (Invulnerable) return;
|
||||||
|
if (area is not Bullet bullet) return;
|
||||||
|
|
||||||
|
if (BulletGroup is BulletOwner.None)
|
||||||
|
{
|
||||||
|
this.Hit(bullet.Damage);
|
||||||
|
bullet.RequestCollisionDestruction();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bullet.BulletInfo.Owner == BulletGroup) return;
|
||||||
|
|
||||||
|
this.Hit(bullet.Damage);
|
||||||
|
bullet.RequestCollisionDestruction();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Hit(float damage, DamageType damageType = DamageType.Neutral)
|
||||||
|
{
|
||||||
|
if (_actor.IsDestroyed) return;
|
||||||
|
if (Invulnerable) return;
|
||||||
|
|
||||||
|
HealthProvider.CurrentResource -= damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void OnDeath()
|
||||||
|
{
|
||||||
|
_actor.IsDestroyed = true;
|
||||||
|
GD.Print("Actor dead");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,8 @@ public partial class EnemyNavigationMovement : MovementHandler
|
||||||
set => _parent.MovementDirection = value;
|
set => _parent.MovementDirection = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsDestroyed => _parent.IsDestroyed;
|
||||||
|
|
||||||
[Export] private bool _navigationEnabled = false;
|
[Export] private bool _navigationEnabled = false;
|
||||||
|
|
||||||
[Export] public float AlarmReactRange = 200f;
|
[Export] public float AlarmReactRange = 200f;
|
||||||
|
|
@ -83,6 +85,7 @@ public partial class EnemyNavigationMovement : MovementHandler
|
||||||
|
|
||||||
public override void PhysicsUpdate(double delta)
|
public override void PhysicsUpdate(double delta)
|
||||||
{
|
{
|
||||||
|
if (IsDestroyed) return;
|
||||||
if (_actorAi.Ai is not AiState.Enabled)
|
if (_actorAi.Ai is not AiState.Enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -149,7 +152,6 @@ public partial class EnemyNavigationMovement : MovementHandler
|
||||||
Shoot();
|
Shoot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
||||||
{
|
{
|
||||||
|
|
||||||
private ActorAi _actorAi;
|
private ActorAi _actorAi;
|
||||||
|
public bool IsDestroyed => _parent.IsDestroyed;
|
||||||
// State accessor
|
// State accessor
|
||||||
|
|
||||||
public override void Init(Actor parent)
|
public override void Init(Actor parent)
|
||||||
|
|
@ -16,6 +16,7 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
||||||
|
|
||||||
public override void PhysicsUpdate(double delta)
|
public override void PhysicsUpdate(double delta)
|
||||||
{
|
{
|
||||||
|
if (IsDestroyed) return;
|
||||||
if (_actorAi.Ai is AiState.Controlled)
|
if (_actorAi.Ai is AiState.Controlled)
|
||||||
base.PhysicsUpdate(delta);
|
base.PhysicsUpdate(delta);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue