Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace BreakOut
{
class Field
{
public static Field generateField()
{
List<Block> blocks = new List<Block>();
for (int j = 0; j < BlockType.BLOCK_TYPES.Length; j++)
for (int i = 0; i < (Game1.WIDTH / Block.WIDTH); i++)
{
Block b = new Block(BlockType.BLOCK_TYPES[j], new Vector2(i * Block.WIDTH, (Block.HEIGHT + 2) * j + 5));
blocks.Add(b);
}
return new Field(blocks);
}
List<Block> blocks;
public Field(List<Block> blocks)
{
this.blocks = blocks;
}
public void Update(GameTime gameTime, Ball b)
{
List<Block> removals = new List<Block>();
foreach (Block o in blocks)
{
if (o.BoundingBox.Intersects(new Rectangle((int)b.pos.X, (int)b.pos.Y, Ball.WIDTH, Ball.HEIGHT))) //collision with blocks
{
removals.Add(o);
}
}
foreach(Block o in removals)
blocks.Remove(o); //removes the blocks, but i need help hitting one at a time
}
public void Draw(GameTime gameTime)
{
foreach (Block b in blocks)
b.Draw(gameTime);
}
}
}
I'm trying to add collision so that when the ball hits against a block, then one of the blocks disappears.
The problem I'm having is: When the ball hits the block, it removes them all in one instance.


Updatelooks correct. Maybe the issue is somewhere else? Have you tried debugging this line-by-line to see where the problem is? – BlueRaja - Danny Pflughoeft Mar 15 '12 at 20:28