/*
* EntityStimulusCentral.cs
* Authors: Mike DeMauro and Brian Murphy
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using tAC_Engine.Graphics.Entities;
using Microsoft.Xna.Framework.Graphics;
using TACParticleEngine.Particles;
using TACParticleEngine;
using Util;
namespace StellarProspector
{
///
/// Defines a central stimulus object
///
internal class EntityStimulusCentral : EntitySpawnable
{
#region Fields
// List of spawnables contained in this spawnable
private List mChildSpawnables = new List();
// Logger for event codes
private Logger mLogger;
// Particle manager reference
private ParticleManager mParticleManager;
// Particle effects
private ParticleEngine mImplosionEffect;
private ParticleEngine mExplosionEffect;
// Values used for graphical positioning
private float mCameraHeight;
private float mCameraWidth;
#endregion
#region Properties
///
/// Sets the Logger to use for event codes
///
public Logger Logger { set { mLogger = value; } }
///
/// Gets/Sets the width of 3D camera used for ParticleEngine
///
public float CameraWidth
{
get { return mCameraWidth; }
set { mCameraWidth = value; }
}
///
/// Gets/Sets the height of 3D camera used for ParticleEngine
///
public float CameraHeight
{
get { return mCameraHeight; }
set { mCameraHeight = value; }
}
///
/// Gets/Sets the ParticleManager used for ParticleEngines
///
public ParticleManager ParticleManager
{
get { return mParticleManager; }
set { mParticleManager = value; }
}
///
/// Gets/Sets the particle effect representing an imploding central stimulus
///
public ParticleEngine ImplosionEffect
{
get { return mImplosionEffect; }
set { mImplosionEffect = value; }
}
///
/// Gets/Sets the particle effect representing an exploding central stimulus
///
public ParticleEngine ExplosionEffect
{
get { return mExplosionEffect; }
set { mExplosionEffect = value; }
}
#endregion
#region Creation
///
/// Creates a new EntityStimulusCentral
///
/// The ContentManager used to load content.
/// The name of the texture to load.
public EntityStimulusCentral(ContentManager content, string textureName)
: base(content, textureName)
{
BlendMode = SpriteBlendMode.AlphaBlend;
Color = Color.GreenYellow;
}
#endregion
#region Maangement
///
/// Add a child sprite that spawns and dies when this entity does
///
public void AddChild(EntitySpawnable s)
{
mChildSpawnables.Add(s);
}
///
/// Loads values in for content dependent objects
///
protected override void LoadContent()
{
base.LoadContent();
mImplosionEffect = mParticleManager.Load("ParticleEffects/Implosion");
mImplosionEffect.SetRandomDirection(true);
mImplosionEffect.SetSplineScale(0.5f);
mExplosionEffect = mParticleManager.Load("ParticleEffects/Explosion");
mExplosionEffect.SetRandomDirection(true);
mExplosionEffect.SetSplineScale(1.4f);
}
#endregion
#region Update
///
/// Updates the central stimulus
///
/// Time that has passed by in game
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
if (mState == SpawnableState.Suspended && !mExplosionEffect.EmitterAlive && mExplosionEffect.EmitterParticlesDone)
Die();
}
#endregion
#region State modifiers
///
/// Sets the color of the stimulus to red, gives it a lifetime
/// of MaxLifeTime and sets state to Alive.
///
/// The sector to spawn in
/// If the stimulus can spawn outside the given sector
public override void Spawn(int sectorNum, bool errorEnabled)
{
Color = new Color(Color.Red.ToVector4() / StellarProspectorGameScreen.MaxIntensity *
StellarProspectorGameScreen.CenterIntensity);
foreach (EntitySpawnable s in mChildSpawnables)
s.Spawn(sectorNum, errorEnabled);
mLifeTime = mMaxLifeTime;
base.Spawn(sectorNum, errorEnabled);
}
///
/// Sets the color of the stimulus to white and the state to Dead.
///
public override void Die()
{
Color = new Color(Color.GreenYellow.ToVector4() / StellarProspectorGameScreen.MaxIntensity *
StellarProspectorGameScreen.CenterIntensity);
foreach (EntitySpawnable s in mChildSpawnables)
s.Die();
base.Die();
if (mLifeTime <= 0)
{
mLogger.Write((int)EventCodes.MissedCentralStimulus, "SP_MissedCentralStimulus");
}
}
///
/// Activates the explosion/implosion effects, indirectly causes the stimulus to die
///
public void Explode()
{
mImplosionEffect.SetEnginePosition(new Vector3(0f, (Y - (GraphicsDevice.Viewport.Height >> 1)) * mCameraHeight, 0f));
mImplosionEffect.SetActive(true);
mExplosionEffect.SetEnginePosition(new Vector3(0f, (Y - (GraphicsDevice.Viewport.Height >> 1)) * mCameraHeight, 0f));
mExplosionEffect.SetActive(true);
SoundManager.SoundManager.PlayEffect("Explosion");
mState = SpawnableState.Suspended;
}
#endregion
}
}