I'm using XNA to make a Bullet Hell Shooter game, and I'm running into some troubles when I try to change the direction in which the bullets move. Been trying to debug for awhile, but haven't gotten anywhere.
The effect that I am trying to have is
I've included all code that might have any dealing with the code.
Custom Box class(really only used for holding the Rectangle and Velocity)
class Box
{
public Rectangle rect;
public Vector2 velo;
public Box()
{
rect = new Rectangle();
}
public Box(Rectangle r, Vector2 v)
{
rect = r;
velo = v;
}
}
Global Declaration:
List<Box> bullets;
List<int> bulletType;
Bullet Logic:
public void bulletStuff()
{
if (bullets.Count > 100)
{
while (bullets.Count > 99)
{
bullets.RemoveAt(0);
bulletType.RemoveAt(0);
}
}
for (int i = 0; i < bullets.Count; i++)
{
bullets[i].rect.Y -= (int)bullets[i].velo.Y;
bullets[i].rect.X += (int)bullets[i].velo.X;
if (bullets[i].rect.Y < 0)
{
bullets.RemoveAt(i);
}
}
}
Collision w/ Enemy & Enemy Logic(Also a Box)
public void enemyStuff()
{
for (int i = 0; i < enemyRects.Count; i++)
{
enemyRects[i].rect.Y += (int)enemyRects[i].velo.Y;
enemyRects[i].rect.X += (int)enemyRects[i].velo.X;
if (enemyRects[i].rect.Y >= 800)
{
enemyRects.RemoveAt(i);
break;
}
if (enemyRects[i].rect.Intersects(playerRect))
{
playerHealth--;
enemyRects.RemoveAt(i);
break;
}
for (int j = 0; j < bullets.Count; j++)
{
if(bullets[j].rect.Intersects(enemyRects[i].rect))
{
bullets.RemoveAt(j);
bulletType.RemoveAt(j);
enemyHealth[i]--;
}
}
if (enemyHealth[i] <= 0)
{
enemyRects.RemoveAt(i);
enemyHealth.RemoveAt(i);
enemiesKilled++;
break;
}
}
}
Update Method
if ((curKeyState.IsKeyDown(Keys.Space) && !preKeyState.IsKeyDown(Keys.Space)) || (curMouseState.LeftButton == ButtonState.Pressed && preMouseState.LeftButton == ButtonState.Pressed))
{//Spawning the Elements
Box Temp;
if (level == 0)
{
Temp = new Box();
Temp.rect = new Rectangle(playerRect.X + (playerRect.Width / 2) - 2, playerRect.Y - (playerRect.Height / 2), 5, 5);
Temp.velo = new Vector2(0, 10);
bullets.Add(Temp);
bulletType.Add(0);
}
else if (level == 1)
{
Temp = new Box();
Temp.rect = new Rectangle(playerRect.X + (playerRect.Width / 2) - 2, playerRect.Y - (playerRect.Height / 2), 10, 10);
Temp.velo = new Vector2(-2, 10);
bullets.Add(Temp);
bulletType.Add(1);
Temp.velo = new Vector2(2, 10);
bullets.Add(Temp);
bulletType.Add(2);
}
else if (level == 2)
{
Temp = new Box();
Temp.rect = new Rectangle(playerRect.X + (playerRect.Width / 2) - 2, playerRect.Y - (playerRect.Height / 2), 10, 10);
Temp.velo = new Vector2(-2, 10);
bullets.Add(Temp);
bulletType.Add(1);
Temp.velo = new Vector2(2, 10);
bullets.Add(Temp);
bulletType.Add(2);
}
else
{
Temp = new Box();
Temp.rect = new Rectangle(playerRect.X + (playerRect.Width / 2) - 2, playerRect.Y - (playerRect.Height / 2), 10, 10);
Temp.velo = new Vector2(-2, 10);
bullets.Add(Temp);
bulletType.Add(1);
Temp.velo = new Vector2(2, 10);
bullets.Add(Temp);
bulletType.Add(2);
}
}
playerRect.X = curMouseState.X - playerRect.Width / 2;
playerRect.Y = curMouseState.Y - playerRect.Height / 2;
levelStuff();
bulletStuff();
enemyStuff();
if (playerHealth == 0)
{
ScreenManager.Instance.addScreen(new TitleScreen(myGame)); //Exits to menu
}
base.Update(gameTime);
}
What is occurring currently is this:

As you can see, it is spawning both new bullets(which are supposed to go opposite of each other) moving in the same direction.