Hello,
Below is my bullet class and what I am trying to accomplish is putting bullets in a list so I can shoot multiple bullets. I am having a really hard time trying to figure this out. When my code is running I hit the spacebar and only one bullet shoots. Can someone please let me know what I am doing wrong or at least point me in the right direction, thanks!
[source]using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace OptimusOrbis.GameObjects
{
public class DefaultBullet : WeaponsManager
{
public Ship Ship { get; set; }
public DefaultBullet defaultBullet { get; set; }
List bullets;
KeyboardState mPreviousKeyboardState;
public DefaultBullet()
: base()
{
Ship = new Ship();
LoadImage("bullet");
rateOfFire = 1;
Damage = 1;
distance = 0;
maxDistance = 500;
bullets = new List();
//bullet will be the same position as the ship
//Ship always stays in the middle so does the bullet
//until it is fired off
Position = Ship.Position;
}
new public void Update()
{
base.Update();
//Allows to use the keyboard
KeyboardState aCurrentKeyboardState = Keyboard.GetState();
mPreviousKeyboardState = aCurrentKeyboardState;
Position += direction * speed * (float)gameManager.GameSpeed;
if (aCurrentKeyboardState.IsKeyDown(Keys.Space))
{
bullets.Add(Position);
for (int i = 0; i < bullets.Count; i++)
{
ShootBullet();
}
}
}
///
/// Shoots the default bullets
///
public void ShootBullet()
{
for (int i = 0; i < bullets.Count; i++)
{
Visible = true;
speed = 10.0f;
direction.X = 1;
}
}
new public void Draw()
{
if (Visible == true)
{
for (int i = 0; i < bullets.Count; i++)
{
base.Draw();
}
}
}
}
}
[/source]