add initial project files and configurations, including EventBus, systems, and resources
This commit is contained in:
64
Code/Systems/DeadliftSystem.cs
Normal file
64
Code/Systems/DeadliftSystem.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Godot;
|
||||
using MaxEffort.Code.Core;
|
||||
|
||||
namespace MaxEffort.Code.Systems;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class DeadliftSystem : BaseLiftSystem
|
||||
{
|
||||
[Export] private float _barHeight = 100f; // Visual height of the lift
|
||||
[Export] private float _holdZoneThreshold = 0.8f; // Must be above 80% to count
|
||||
[Export] private Node2D _barVisual;
|
||||
[Export] private Vector2 _startPos;
|
||||
[Export] private Vector2 _endPos;
|
||||
|
||||
private float _currentBarHeight = 0f;
|
||||
private float _holdTimer = 0f;
|
||||
|
||||
public override void Initialize(float targetTime, float gravity)
|
||||
{
|
||||
base.Initialize(targetTime, gravity);
|
||||
_holdTimer = 0f;
|
||||
}
|
||||
|
||||
protected override void HandleEffort(float effortDelta)
|
||||
{
|
||||
_currentBarHeight += PowerPerClick * effortDelta;
|
||||
_currentBarHeight = Mathf.Min(_currentBarHeight, _barHeight);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (IsLiftComplete) return;
|
||||
|
||||
var dt = (float)delta;
|
||||
|
||||
if (_currentBarHeight > 0)
|
||||
{
|
||||
_currentBarHeight -= Gravity * dt;
|
||||
_currentBarHeight = Mathf.Max(0, _currentBarHeight);
|
||||
}
|
||||
|
||||
var visualRatio = _currentBarHeight / _barHeight; // 0.0 to 1.0 (Height)
|
||||
|
||||
if (visualRatio >= _holdZoneThreshold && ActiveHazardCount == 0)
|
||||
{
|
||||
_holdTimer += dt;
|
||||
EventBus.PublishCameraTrauma(0.15f * dt);
|
||||
}
|
||||
|
||||
EventBus.PublishLiftVisualHeight(visualRatio);
|
||||
EventBus.PublishLiftProgress(_holdTimer / TargetValue);
|
||||
|
||||
if (_barVisual != null)
|
||||
{
|
||||
_barVisual.Position = _startPos.Lerp(_endPos, visualRatio);
|
||||
}
|
||||
|
||||
if (_holdTimer >= TargetValue)
|
||||
{
|
||||
EventBus.PublishCameraTrauma(1.0f);
|
||||
EventBus.PublishLiftCompleted(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user