# Bullets Spawning in same direction [closed]

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);
}
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);
Temp.velo = new Vector2(2, 10);
}
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);
Temp.velo = new Vector2(2, 10);
}
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);
Temp.velo = new Vector2(2, 10);
}

}

playerRect.X = curMouseState.X - playerRect.Width / 2;
playerRect.Y = curMouseState.Y - playerRect.Height / 2;

levelStuff();
bulletStuff();
enemyStuff();

if (playerHealth == 0)
{
}

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.

## closed as too localized by MichaelHouse♦, Sean Middleditch, Josh♦, Trevor Powell, bummzackFeb 23 '13 at 10:45

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

• What debugging steps have you taken already? – MichaelHouse Feb 22 '13 at 0:19
• @Byte56 I've already redone the spawning code, as well as tried to figure out where the second bullet spawned is. I discovered that they are spawning in the exact same place, although, they are not moving in the same direction. In the picture I drew the bullets by number, but they overlap, thus I'm led to believe that the vaie of "Temp" when spawning bullets does not change after I reassign the value of it's X velocity to 2, instead of -2. – jatmdm Feb 22 '13 at 0:21
• Even though you're adding the bullet to the list, if you modify it after that, you're still modifying the original. So from the looks of it, you're adding two bullets every time both of type two and with a velocity of (2, 10). You have to create a new bullet and modify its value if you want to have different bullets. BTW, I'm voting to close this as too localized. This isn't the place for people to debug your code for you. – MichaelHouse Feb 22 '13 at 0:24
• Thank you very much @Byte56 , it worked just as you said. I appreciate the help. – jatmdm Feb 22 '13 at 0:27

Temp = new Box(); //create a new box