#region File Description
//-----------------------------------------------------------------------------
// Projectiles.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics;
#endregion
namespace Spacewar
{
///
/// Projectiles handles collections of projectiles shot from the retro or evolved ship.
/// Its useful to have a a parent group because in Retro mode we want to batch render them
///
public class Projectiles : SceneItem
{
public Projectiles(Game game)
: base(game)
{
Projectile.ProjectileCount[0] = 0;
Projectile.ProjectileCount[1] = 0;
Projectile.ProjectileCount[2] = 0;
}
///
/// Creates a group of projectiles
///
/// Which player shot the bullet
/// Start position of projectile
/// Initial velocity of projectile
/// Direction projectile is facing
/// Game time that this projectile was shot
/// The particles to add to for effects
public virtual void Add(PlayerIndex player, Vector3 position, Vector3 velocity, float angle, TimeSpan time, Particles particles)
{
ProjectileType projectileType = SpacewarGame.Players[(int)player].ProjectileType;
Vector3 offset = Vector3.Zero;
if (SpacewarGame.Players[(int)player].ProjectileType == ProjectileType.DoubleMachineGun)
{
//Get a perpendicular vector to the direction of fire to offset the double shot
offset.X = -velocity.Y;
offset.Y = velocity.X;
offset.Normalize();
offset *= 10.0f;
}
for (int i = 0; i < SpacewarGame.Settings.Weapons[(int)projectileType].Burst; i++)
{
//If we are not up to max then we can add bullets
if (Projectile.ProjectileCount[(int)player] < SpacewarGame.Settings.Weapons[(int)projectileType].Max)
{
Add(new Projectile(GameInstance, player, position + velocity * i * .1f + offset, velocity, angle, time, particles));
if (offset != Vector3.Zero)
{
Add(new Projectile(GameInstance, player, position + velocity * i * .1f - offset, velocity, angle, time, particles));
}
}
}
}
///
/// Removes all elements from the .
/// This method hides the real method and just marks the items as ready to be deleted
/// to avoid updating the collection while in a loop and to allow us to maintain the correct
/// bullet count
///
public new void Clear()
{
foreach (Projectile projectile in this)
{
projectile.DeleteProjectile();
}
}
}
}