I'm writing collision code for my breakout clone. Thanks to the people at allegro.cc I have gotten this far. Now I need more help with collision detection. I can find out if the ball is within the block and have it bounce off the left side, but that's all. anymore help?
Code:for(x =0; x < MAX_ROW; x++) { for(y = 0; y < MAX_COL; y++) { if (ball.x > blocks[x][y].x && ball.x <= blocks[x][y].width && ball.y > blocks[x][y].y && ball.y <= blocks[x][y].height) { if(blocks[x][y].color > 0) { paddle.score += blocks[x][y].color*10; blocks[x][y].color = 0; if(ball.x > blocks[x][y].x) ball.dx = -BALL_DELTA; // bounce left else if(ball.x <= blocks[x][y].width) ball.dx = BALL_DELTA; // bounce right else if(ball.y > blocks[x][y].y) ball.dy = -BALL_DELTA; // bounce up else if(ball.y <= blocks[x][y].height) ball.dy = BALL_DELTA; // bounce down numOfBlocks--; } } } }



LinkBack URL
About LinkBacks


