#region File Description
//-----------------------------------------------------------------------------
// MineProjectile.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
#endregion
namespace NetRumble
{
///
/// A mine projectile.
///
public class MineProjectile : Projectile
{
#region Constants
///
/// The initial speed of this projectile.
///
const float initialSpeed = 64f;
///
/// The amount of drag applied to velocity per second,
/// as a percentage of velocity.
///
const float dragPerSecond = 0.9f;
///
/// The radians-per-second that this object rotates at.
///
const float rotationRadiansPerSecond = 1f;
#endregion
#region Static Graphics Data
///
/// Texture for all mine projectiles.
///
private static Texture2D texture;
///
/// The particle-effect manager which recieves the effects from mines.
///
public static ParticleEffectManager ParticleEffectManager;
#endregion
#region Initialization
///
/// Constructs a new mine projectile.
///
/// The ship that fired this projectile, if any.
/// The initial direction for this projectile.
public MineProjectile(Ship owner, Vector2 direction)
: base(owner, direction)
{
// set the gameplay data
this.velocity = initialSpeed * direction;
// set the collision data
this.radius = 10f;
this.mass = 5f;
// set projectile data
this.duration = 15f;
this.damageAmount = 200f;
this.damageOwner = false;
this.damageRadius = 80f;
}
#endregion
#region Updating Methods
///
/// Update the mine.
///
/// The amount of elapsed time, in seconds.
public override void Update(float elapsedTime)
{
base.Update(elapsedTime);
this.velocity -= velocity * (elapsedTime * dragPerSecond);
this.rotation += elapsedTime * rotationRadiansPerSecond;
}
#endregion
#region Drawing Methods
///
/// Draw the mine.
///
/// The amount of elapsed time, in seconds.
/// The SpriteBatch object used to draw.
public override void Draw(float elapsedTime, SpriteBatch spriteBatch)
{
// ignore the parameter color if we have an owner
base.Draw(elapsedTime, spriteBatch, texture, null, Color.White);
}
#endregion
#region Interaction Methods
///
/// Kills this object, in response to the given GameplayObject.
///
/// The GameplayObject responsible for the kill.
///
/// If true, the object dies without any further effects.
///
public override void Die(GameplayObject source, bool cleanupOnly)
{
if (active)
{
if (!cleanupOnly)
{
// play the explosion sound effect
AudioManager.PlaySoundEffect("explosion_large");
// play the mine particle-effect
if (ParticleEffectManager != null)
{
ParticleEffectManager.SpawnEffect(
ParticleEffectType.MineExplosion, Position);
}
}
}
base.Die(source, cleanupOnly);
}
#endregion
#region Static Graphics Methods
///
/// Load all of the static graphics content for this class.
///
/// The content manager to load with.
public static void LoadContent(ContentManager contentManager)
{
// safety-check the parameters
if (contentManager == null)
{
throw new ArgumentNullException("contentManager");
}
// load the texture
texture = contentManager.Load("Textures/mine");
}
///
/// Unload all of the static graphics content for this class.
///
public static void UnloadContent()
{
texture = null;
}
#endregion
}
}