/*
* PhotonTorpedo.cs
* Authors: August Zinsser, Adam Nabinger
* 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 Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TACParticleEngine.Particles;
namespace MaritimeDefender
{
///
/// The lasers that the player fires at meteors or other ships
///
public class PhotonTorpedo : Entity
{
#region Fields
///
/// Depth that the lasers spawn at (should be the same as the player ship)
///
protected float mSpawnDepth;
///
/// How far the laser travels before fizzling out
///
protected float mKillDepth;
///
/// If the laser is alive or not
///
protected new bool mAlive = true;
///
/// Used to determine whether the lasers are travelling away from the player or towards it
///
protected bool mIsGoingAway;
///
/// Friendly lasers are fired from the player, non-friendly lasers can damage the player
///
protected bool mFriendly = true;
///
/// How much damage is dealt to a ship that collides with this laser
///
protected int mDamage;
///
/// Size of this entity in space3D coordinates
///
protected Vector3 mSpace3DSize;
///
/// The level of the weapon for the purpose of upgrades
/// Note currently not implemented
///
protected int mLevel;
///
/// Reference to the game to access the particle manager
///
protected MaritimeDefender mGame;
///
/// Whether or not the photon particle effect should be used
///
protected bool mUsePhotonEffect;
///
/// The particle effect for displaying the photon torpedo with
///
protected ParticleEngine mPhotonTorpedo;
#endregion
#region Properties
///
/// Gets the 3-dimensional size of the photon torpedo
///
public override Vector3 Size { get { return mSpace3DSize; } }
///
/// Gets/Sets the width of the photon torpedo
///
public override float Width {
get { return mSpace3DSize.X; }
set { mSpace3DSize.X = value; }
}
///
/// Gets/Sets the width of the photon torpdeo
///
public override float Height {
get { return mSpace3DSize.Y; }
set { mSpace3DSize.Y = value; }
}
///
/// Gets/Sets whether or not the photon torpedo has been fired from the player or an ally of the player
///
public bool Friendly {
get { return mFriendly; }
set { mFriendly = value; }
}
///
/// Gets/Sets the damage done by the photon torpedo upon collision
///
public int Damage {
get { return mDamage; }
set { mDamage = value; }
}
///
/// Gets/Sets the whether or not the photon torpedo is still alive
///
public bool Alive {
get { return mAlive; }
set {
mAlive = value;
mPhotonTorpedo.SetActive(value);
}
}
#endregion
#region Predicates
///
/// Defines when the photon torpedo is no longer considered alive so that it may be disposed of
///
public new static readonly Predicate NotAlive = new Predicate(delegate(PhotonTorpedo o)
{
return !o.mAlive;
});
#endregion
#region Creation
///
/// Constructor
///
/// Whether or not the base particle effect should be used.
/// Note: this is usually turned off for derived classes when different visual effects are desired.
/// Whether or not the photon torpedo should rotate clockwise
/// The level of the photon torpedo for modifying damage, firing rate, and visuals of it.
/// The 3-dimensional location at which the photon torpedo spawns at
/// The width of the photon torpedo
/// The height of the photon torpedo
/// The depth of the photon torpdeo
/// The speed at which the photon torpdeo moves
/// The depth at which the photon torpedo spawns at
/// The depth at which the photon torpedo will be destroyed at upon reaching
/// The reference to the current Maritime Defender game screen
public PhotonTorpedo(bool usePhotonEffect, bool clockwise, int level, Vector3 spawnLocation, float width,
float height, float depth, float speed, float spawnDepth, float killDepth, MaritimeDefender game)
{
mUsePhotonEffect = usePhotonEffect;
mSpace3DSize = new Vector3(width, height, depth);
mLevel = level;
mPos = spawnLocation;
mVel.Z = speed;
mSize.Z = width * 2;
mSpawnDepth = spawnDepth;
mKillDepth = killDepth;
mIsGoingAway = speed > 0;
mGame = game;
LoadContent(game.Content);
}
#endregion
#region Management
///
/// Loads in needed content
///
/// The current content manager
public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content)
{
if (mUsePhotonEffect)
{
mPhotonTorpedo = mGame.MMParticleManager.Load("ParticleEffects/PhotonTorpedo");
mPhotonTorpedo.SetEngineColor(new Vector4(0.2f + 0.2f * mLevel, 0.25f + 0.25f * (mLevel % 3),
1f - 0.1f * mLevel, 0.25f + 0.15f * mLevel), false);
mPhotonTorpedo.SetEngineSize(new Vector2(20f + 10f * mLevel, 20f + 10f * mLevel));
mPhotonTorpedo.SetEnginePosition(MaritimeDefender.ConvertPosition(mPos));
mPhotonTorpedo.SetActive(true);
}
base.LoadContent(content);
}
///
/// Disposes of content dependent objects
///
public override void UnloadContent()
{
mPhotonTorpedo.SetActive(false);
mPhotonTorpedo.ToDestory = true;
base.UnloadContent();
}
#endregion
#region Update
///
/// Scroll the torpedoes
///
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
// Update the photon's position
if (mIsGoingAway && mPos.Z > mKillDepth ||
!mIsGoingAway && mPos.Z < mKillDepth)
{
mPhotonTorpedo.SetActive(false);
mPhotonTorpedo.ToDestory = true;
mAlive = false;
}
mPhotonTorpedo.SetEnginePosition(MaritimeDefender.ConvertPosition(mPos));
}
#endregion
#region DeactivateEffect
///
/// Deactives the particle effect for the photon torpedo
///
public void DeactivateEffect()
{
mPhotonTorpedo.SetActive(false);
}
#endregion
}
}