mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 23:05:53 +00:00
health station
This commit is contained in:
parent
cc1fa2cdc6
commit
f7cbd7d171
8 changed files with 268 additions and 11 deletions
117
Scripts/Activables/HealthStation.cs
Normal file
117
Scripts/Activables/HealthStation.cs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
||||
public partial class HealthStation : Activable
|
||||
{
|
||||
[Export]
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
[Export]
|
||||
public float HealthPerSecond { get; private set; } = 10f;
|
||||
|
||||
[Export]
|
||||
public float ShieldPerSecond { get; private set; } = 10f;
|
||||
|
||||
private AnimatedSprite2D _animatedSprite;
|
||||
|
||||
private GpuParticles2D _particles;
|
||||
|
||||
private bool _isHealing = false;
|
||||
|
||||
private PlayerMovement _cachedPlayer;
|
||||
|
||||
private double _healingTimer = 0;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_particles = GetNode<GpuParticles2D>("./Particles");
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||
|
||||
_particles.Emitting = false;
|
||||
|
||||
if (IsEnabled)
|
||||
{
|
||||
_animatedSprite.Play("Active");
|
||||
}
|
||||
else
|
||||
{
|
||||
_animatedSprite.Play("Default");
|
||||
}
|
||||
|
||||
_healingTimer = 0;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
base._Process(delta);
|
||||
|
||||
if (_isHealing && _cachedPlayer != null)
|
||||
{
|
||||
_healingTimer += delta;
|
||||
|
||||
if (_healingTimer >= 1)
|
||||
{
|
||||
_cachedPlayer.CurrentHealth += HealthPerSecond;
|
||||
_cachedPlayer.CurrentShield += ShieldPerSecond;
|
||||
|
||||
_healingTimer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
switch (activationType)
|
||||
{
|
||||
case ActivationType.Toggle:
|
||||
// Enables/Disables teleporter
|
||||
break;
|
||||
case ActivationType.Enable:
|
||||
// Enables Teleporter
|
||||
IsEnabled = true;
|
||||
_animatedSprite.Play("Active");
|
||||
break;
|
||||
case ActivationType.Disable:
|
||||
IsEnabled = false;
|
||||
_animatedSprite.Play("Default");
|
||||
// Disables Teleporter
|
||||
break;
|
||||
case ActivationType.Use:
|
||||
// Teleports
|
||||
break;
|
||||
case ActivationType.Destroy:
|
||||
// Destroys
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_body_entered(CharacterBody2D area)
|
||||
{
|
||||
// Heal player if active
|
||||
if (!IsEnabled) return;
|
||||
if (area is not PlayerMovement player) return;
|
||||
|
||||
_cachedPlayer = player;
|
||||
|
||||
_isHealing = true;
|
||||
_particles.Emitting = true;
|
||||
}
|
||||
|
||||
private void _on_body_exited(CharacterBody2D area)
|
||||
{
|
||||
if (!_isHealing) return;
|
||||
if (!IsEnabled) return;
|
||||
if (area is not PlayerMovement player) return;
|
||||
|
||||
// Stop healing player if active
|
||||
|
||||
_isHealing = false;
|
||||
_particles.Emitting = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue