add initial project files and configurations, including EventBus, systems, and resources
This commit is contained in:
66
Code/Systems/BaseLiftSystem.cs
Normal file
66
Code/Systems/BaseLiftSystem.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Godot;
|
||||
using MaxEffort.Code.Core;
|
||||
using MaxEffort.Code.Data;
|
||||
|
||||
namespace MaxEffort.Code.Systems;
|
||||
|
||||
public abstract partial class BaseLiftSystem : Node
|
||||
{
|
||||
[Export] protected float PowerPerClick = 5f;
|
||||
[Export] protected float Gravity = 2f;
|
||||
[Export] protected float TargetValue = 100f; // Distance OR Time
|
||||
|
||||
protected float CurrentProgress = 0f;
|
||||
protected bool IsLiftComplete = false;
|
||||
protected int ActiveHazardCount = 0;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
EventBus.OnLiftEffortApplied += ApplyPower;
|
||||
EventBus.OnHazardSpawned += OnHazardSpawned;
|
||||
EventBus.OnHazardResolved += OnHazardResolved;
|
||||
EventBus.OnLiftCompleted += OnLiftCompleted;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
EventBus.OnLiftEffortApplied -= ApplyPower;
|
||||
EventBus.OnHazardSpawned -= OnHazardSpawned;
|
||||
EventBus.OnHazardResolved -= OnHazardResolved;
|
||||
EventBus.OnLiftCompleted -= OnLiftCompleted;
|
||||
}
|
||||
|
||||
public virtual void Initialize(float target, float gravity)
|
||||
{
|
||||
TargetValue = target;
|
||||
Gravity = gravity;
|
||||
CurrentProgress = 0f;
|
||||
IsLiftComplete = false;
|
||||
ActiveHazardCount = 0;
|
||||
}
|
||||
|
||||
private void OnLiftCompleted(bool success)
|
||||
{
|
||||
IsLiftComplete = true;
|
||||
}
|
||||
|
||||
private void OnHazardResolved(HazardType _)
|
||||
{
|
||||
ActiveHazardCount--;
|
||||
if (ActiveHazardCount < 0) ActiveHazardCount = 0;
|
||||
}
|
||||
|
||||
private void OnHazardSpawned(HazardType _)
|
||||
{
|
||||
ActiveHazardCount++;
|
||||
}
|
||||
|
||||
private void ApplyPower(float effortDelta)
|
||||
{
|
||||
if (IsLiftComplete || ActiveHazardCount > 0) return;
|
||||
HandleEffort(effortDelta);
|
||||
}
|
||||
|
||||
protected abstract void HandleEffort(float effortDelta);
|
||||
public abstract override void _Process(double delta);
|
||||
}
|
||||
Reference in New Issue
Block a user