mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-22 17:53:46 +00:00
Explosions
This commit is contained in:
parent
4bc76cc475
commit
e1d6afa512
21 changed files with 323 additions and 24 deletions
|
|
@ -4,12 +4,13 @@ using System.Diagnostics;
|
|||
|
||||
public partial class Barrel : Area2D, IDestructible
|
||||
{
|
||||
[Export] public float Health = 1f;
|
||||
|
||||
[Export]
|
||||
public float Health = 1f;
|
||||
[Export] public float ExplosionRadius = 1;
|
||||
|
||||
[Export]
|
||||
public float ExplosionRadius = 1;
|
||||
[Export] public float ExplosionDamage = 1;
|
||||
|
||||
[Export] public PackedScene DebrisScene { get; set; }
|
||||
|
||||
private float _currentHealth;
|
||||
|
||||
|
|
@ -26,23 +27,34 @@ public partial class Barrel : Area2D, IDestructible
|
|||
{
|
||||
}
|
||||
|
||||
public void Explode() {
|
||||
private void Explode()
|
||||
{
|
||||
Debug.WriteLine("Boom");
|
||||
CreateDebris();
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
private void CreateDebris()
|
||||
{
|
||||
if (DebrisScene == null) return;
|
||||
var debris = DebrisScene.Instantiate<Barrel>();
|
||||
Owner.AddChild(debris);
|
||||
debris.Transform = this.GlobalTransform;
|
||||
debris.Position = this.Position;
|
||||
}
|
||||
|
||||
public void Hit(float damage)
|
||||
{
|
||||
if (_isDestroyed) return;
|
||||
|
||||
_currentHealth -= damage;
|
||||
if (!(_currentHealth <= 0)) return;
|
||||
_isDestroyed = true;
|
||||
Explode();
|
||||
|
||||
// TODO: Change sprite
|
||||
}
|
||||
|
||||
public bool IsDestroyed()
|
||||
{
|
||||
return _isDestroyed;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue