#region File Description
//-----------------------------------------------------------------------------
// LaserProjectile.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 laser bolt projectile.
///
public class LaserProjectile : Projectile
{
#region Constants
///
/// The length of the laser-bolt line, expressed as a percentage of velocity.
///
const float initialSpeed = 640f;
#endregion
#region Static Graphics Data
///
/// Texture for all laser projectiles.
///
private static Texture2D texture;
///
/// The particle-effect manager which receives the effects from lasers.
///
public static ParticleEffectManager ParticleEffectManager;
#endregion
#region Initialization
///
/// Constructs a new laser projectile.
///
/// The ship that fired this projectile, if any.
/// The initial direction for this projectile.
public LaserProjectile(Ship owner, Vector2 direction)
: base(owner, direction)
{
// set the gameplay data
this.velocity = initialSpeed * direction;
// set the collision data
this.radius = 4f;
this.mass = 0.5f;
// set the projectile data
this.duration = 5f;
this.damageAmount = 20f;
this.damageRadius = 0f;
this.damageOwner = false;
}
#endregion
#region Drawing Methods
///
/// Draw the laser projectile.
///
/// 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,
owner != null ? owner.Color : 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)
{
// display the laser explosion
if (!cleanupOnly && (ParticleEffectManager != null))
{
ParticleEffectManager.SpawnEffect(ParticleEffectType.LaserExplosion,
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/laser");
}
///
/// Unload all of the static graphics content for this class.
///
public static void UnloadContent()
{
texture = null;
}
#endregion
}
}