This seems really strange to me. I've tried over and over to fix it myself, but I just can't see what the problem is. I'm making a breakout clone, you know where you control the paddle and you hit the ball and try to break all the blocks without the ball hitting the bottom of the screen. The problem is, when the ball hits one of the blocks, it destroys the block it hit, but it also destroys the block 1 row below and 10 columns to the left. These are the functions that have to do with displaying and destroying the blocks
Code:
void TestBallBlock()
{
for(int i = 0; i < 14; i++)
{
bx = 43*i + 18;
for(int k = 0; k < 9; k++)
{
by = 43*k + 18;
if(blocks[k][i] == 1)
{
//Check if ball has collided with block
if(DetectCollision(ball,ballx,bally,block,bx,by))
{
KillFunction(1,k,i);
}
}
}
}
}
bool DetectCollision(BITMAP *A, int ax, int ay, BITMAP *B, int bx, int by)
{
int aright = ax + A->w;
int abottom = ay + A->h;
int bright = bx + B->w;
int bbottom = by + B->h;
return !(aright < bx || bright < ax || abottom < by || bbottom < ay);
}
void DrawBlocks()
{
//Draw all the blocks
for(int i = 0; i < 14; i++)
{
bx = 43*i + 18;
for(int k = 0; k < 9; k++)
{
by = 43*k + 18;
if(blocks[k][i] == 1)
{
draw_sprite(buffer,block,bx,by);
}
}
}
}
void KillFunction(int kf, int k, int i)
{
//Eventually there will be more of these once I make more types of blocks
switch (kf)
{
case 1:
blocks[k][i] = 0;
balldy = -balldy;
break;
}
}
[/I]I know it's a lot to look over, but I would really appreciate it if someone would take the time to figure this out for me. It's probably something really obvious that I missed. Tell me if you have an idea or if you think I should give more information or code. Thanks!