Reputation: 1
The bullets in my code seem to be shooting the invaders, since the invaders disappear. However there is no bullet coming out of the tank and hitting the invaders. I don't know where the bullet went.
Initialize Code for bullet:
recBullet = new Rectangle();
isRight = true;
isShotFired = false;
isBulletOut = false;
isBulletAlive = true;
Update Code:
KeyboardState keys = Keyboard.GetState();
if ((keys.IsKeyDown(Keys.Space) == true || oldState.IsKeyUp(Keys.Space) == false))
{
recBullet.X = recTank.X + recTank.Width / 2;
recBullet.Y = screenHeight;
isShotFired = true;
isBulletAlive = true;
}if (isShotFired)
{
recBullet.Y -= 10;
}
if (recBullet.Y <= 0)
{
isShotFired = false;
}
for (int x = 0; x < numberOfXInvaders; x++)
{
for (int y = 0; y < numberofYInvaders; y++)
{
if (isBulletAlive)
{
if (recBullet.Intersects(recInvader[x, y]))
{
if (!isInvaderDead[x, y])
{
isInvaderDead[x, y] = true;
isBulletAlive = false;
}
}
}
}
}
oldState = keys;
Draw Code:
if (isBulletAlive)
{
spriteBatch.Draw(texBullet, recBullet, Color.Green);
}
I appreciate any help I can get for this! Thanks.
Upvotes: 0
Views: 58
Reputation: 2070
Do the following steps:
Upvotes: 1