/* Sparx
* Copyright August Zinsser 2007
* This program is distributed under the terms of the GNU General Public License
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace Pina3D.Particles
{
///
/// All objects that can be saved to and loaded from a .spx file
///
public abstract class SparxEntity : ICloneable
{
protected string mName; // Used for bookeeping
public string Name { set { mName = value; } get { return mName; } }
public SparxEntity()
: this ("")
{
}
public SparxEntity(string name)
{
mName = name;
}
///
/// Returns a new instance that is like this one was when it was created
///
///
public abstract Object Clone();
}
///
/// Sparx entities that are born and may die
///
public class SparxMortalEntity : SparxEntity
{
protected float mLifeExpectancy; // Varies, whereas some children's "lifeSpan" variable serves as an initializer for mLifeExpectancy
protected float mAge;
protected bool mAlive;
protected bool mImmortal;
///
/// Time from birth to expected death. This value may vary as the entity exists.
///
public virtual float LifeExpectancy { set { mLifeExpectancy = value; } get { return mLifeExpectancy; } }
///
/// The time that has elapsed since this emission was created.
///
public virtual float Age { set { mAge = value; } get { return mAge; } }
public bool Alive { set { mAlive = value; } get { return mAlive; } }
public bool Immortal { set { mImmortal = value; } get { return mImmortal; } }
public SparxMortalEntity(string name, float lifeSpan, bool immortal)
: base (name)
{
mLifeExpectancy = lifeSpan;
mAge = 0;
mImmortal = immortal;
mAlive = true;
}
///
/// Allows children to instantiate blank copies of themselves for cloning
///
protected SparxMortalEntity() { }
///
/// Ages the entity and kills it if it gets too old
///
public virtual void Update()
{
mAge += Pina.ElapsedSeconds;
// Death
if (!mImmortal && mAge > mLifeExpectancy)
{
mAlive = false;
}
}
public override Object Clone()
{
return new SparxMortalEntity(mName, mLifeExpectancy, mImmortal);
}
}
}