mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 03:35:54 +00:00
Resource provider
This commit is contained in:
parent
1fbdc3ddd7
commit
ba21b30a4d
3 changed files with 58 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=36 format=3 uid="uid://bqjcwxene73l2"]
|
||||
[gd_scene load_steps=37 format=3 uid="uid://bqjcwxene73l2"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Components/Actors/Actor.cs" id="1_k5cyk"]
|
||||
[ext_resource type="Texture2D" uid="uid://hukxr2e63gky" path="res://Sprites/Actors/Robot3.png" id="2_wt8wl"]
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
[ext_resource type="Script" path="res://Scripts/Components/Actors/ActorAi.cs" id="6_jlcsg"]
|
||||
[ext_resource type="Script" path="res://Scripts/Components/Actors/EnemyNavigationMovement.cs" id="7_fvl12"]
|
||||
[ext_resource type="Script" path="res://Scripts/Components/ProximityPlayerDetection.cs" id="8_62r5q"]
|
||||
[ext_resource type="Script" path="res://Scripts/Components/Actors/ActorResourceProvider.cs" id="9_2ocwk"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_spe0p"]
|
||||
atlas = ExtResource("2_wt8wl")
|
||||
|
|
@ -277,6 +278,10 @@ avoidance_enabled = true
|
|||
debug_enabled = true
|
||||
debug_path_custom_color = Color(1, 0, 0, 1)
|
||||
|
||||
[node name="HealthProvider" type="Node2D" parent="."]
|
||||
script = ExtResource("9_2ocwk")
|
||||
ResourceName = "Health"
|
||||
|
||||
[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="velocity_computed" from="NavigationAgent2D" to="NavigationMovementProvider" method="_on_navigation_agent_2d_velocity_computed"]
|
||||
|
|
|
|||
51
Scripts/Components/Actors/ActorResourceProvider.cs
Normal file
51
Scripts/Components/Actors/ActorResourceProvider.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class ActorResourceProvider : Node2D
|
||||
{
|
||||
[Export]
|
||||
public string ResourceName { get; private set; }
|
||||
|
||||
[Export]
|
||||
public float MaxResource { get; set; } = 10f;
|
||||
|
||||
private float _currentResource = 0f;
|
||||
|
||||
[Signal]
|
||||
public delegate void ResourceChangedEventHandler(float newValue, float maxValue);
|
||||
|
||||
[Signal]
|
||||
public delegate void ResourceMaxedEventHandler(float maxValue);
|
||||
|
||||
[Signal]
|
||||
public delegate void ResourceDepletedEventHandler();
|
||||
|
||||
public float CurrentResource
|
||||
{
|
||||
get => _currentResource;
|
||||
set
|
||||
{
|
||||
if (_currentResource != value)
|
||||
{
|
||||
_currentResource = value;
|
||||
|
||||
if (_currentResource > MaxResource) {
|
||||
_currentResource = MaxResource;
|
||||
EmitSignal(SignalName.ResourceMaxed, MaxResource);
|
||||
}
|
||||
else if (_currentResource <= 0)
|
||||
{
|
||||
EmitSignal(SignalName.ResourceDepleted);
|
||||
}
|
||||
|
||||
EmitSignal(SignalName.ResourceChanged, _currentResource, MaxResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void FillResource()
|
||||
{
|
||||
CurrentResource = MaxResource;
|
||||
}
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
private bool _canMove = true;
|
||||
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float newHealth, float MaxHealth);
|
||||
public delegate void HealthChangedEventHandler(float newHealth, float maxHealth);
|
||||
|
||||
[Signal]
|
||||
public delegate void ShieldChangedEventHandler(float newShield, float maxShield);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue