mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 03:15:54 +00:00
60 lines
1.1 KiB
C#
60 lines
1.1 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Diagnostics;
|
|
|
|
public partial class Barrel : Area2D, IDestructible
|
|
{
|
|
[Export] public float Health = 1f;
|
|
|
|
[Export] public float ExplosionRadius = 1;
|
|
|
|
[Export] public float ExplosionDamage = 1;
|
|
|
|
[Export] public PackedScene DebrisScene { get; set; }
|
|
|
|
private float _currentHealth;
|
|
|
|
private bool _isDestroyed = false;
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready()
|
|
{
|
|
_currentHealth = Health;
|
|
}
|
|
|
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
public override void _Process(double delta)
|
|
{
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
public bool IsDestroyed()
|
|
{
|
|
return _isDestroyed;
|
|
}
|
|
}
|