I've been working on this for several weeks now and I can get it to work as It to work. It's almost there I guess there is just something I'm missing. I basically cant get the collision detection betwen the blocks and the ball to work like I wnat them to work.
The ball still has a chance to plow loads of block within seconds. I would love to hear form people who have had a similiar problem.
Here's the code;
private function checkCollision():void
{
grdx = Math.floor((ball.x) / 28);
grdy = Math.floor((ball.y) / 14);
ngrdx = Math.floor((ball.x + dx) / 28);
ngrdy = Math.floor((ball.y + dy) / 14);
if (grdy <= level.length - 1 && ngrdy <= level.length - 1 && grdy >= 0 && ngrdy >= 0)
{
if(level[grdy][ngrdx] > 0)
{
level[grdy][ngrdx] = 0;
bnm = "Block_" + grdy + "_" + ngrdx;
if (this.getChildByName(bnm) != null)
{
this.removeChild(this.getChildByName(bnm));
dx *= -1;
totalBreaks++;
trace("Hit on X");
trace("Block: " + totalBreaks + " / " + totalBlocks);
}
}
else if(level[ngrdy][grdx] > 0)
{
bnm = "Block_" + ngrdy + "_" + grdx;
level[ngrdy][grdx] = 0;
if (this.getChildByName(bnm) != null)
{
this.removeChild(this.getChildByName(bnm));
dy *= -1;
totalBreaks++;
trace("Hit on Y");
trace("Block: " + totalBreaks + " / " + totalBlocks);
}
}
if(level[ngrdy][ngrdx] > 0)
{
bnm = "Block_" + ngrdy + "_" + ngrdx;
level[ngrdy][ngrdx] = 0;
if (this.getChildByName(bnm) != null)
{
this.removeChild(this.getChildByName(bnm));
dy *= -1;
dx *= -1;
totalBreaks++;
trace("hit on X,Y");
trace("Block: " + totalBreaks + " / " + totalBlocks);
}
}
}
}