I'm trying to make a simple brick breaker game. I have everything created with collision and simple physics. The ball bounces off the paddle and walls, but I'm having trouble with the bricks. I can get the ball to bounce off the bricks, I'm just not experienced enough to know how to make the brick disappear. The bricks are in an array. Is there some way to remove a brick/specific index of an array?
This is how I create the blocks
int blockCount=0;
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 5; y++)
{
blocks[blockCount] = Content.Load<Texture2D>("Block");
blocksPosition[blockCount].X = 95 + (x * 75);
blocksPosition[blockCount].Y = 20 + (y * 50);
blockCount++;
}
}
This is how I do collision and how I would implement the brick removal
public void DetectBlockBallCollision()
{
for (int i = 0; i<40; i++)
{
if ((ballPosition.Y + ball.Height) >= blocksPosition[i].Y &&
(ballPosition.Y + ball.Height) < (blocksPosition[i].Y+75) &&
(ballPosition.X + ball.Width) > blocksPosition[i].X &&
ballPosition.X < (blocksPosition[i].X + blocks[i].Width))
{
movingUp = false;
//whatever would get rid of block;
}
}
}
ActiveorVisibleproperty on the brick and then use that to determine whether or not to draw it and/or calculate collisions for it. You could also just set the element tonulland check for null in your loop. - TyCobb