I'm prorgramming a breakout/paddle game and its comming together nicely, but now I have gotten to the Collision Detection(when the ball hits the blocks)...
I create objects(BOB's) using my engine which has a lot of wrapper functions, fx Collison_BOBS:
PHP Code:
int Collision_BOBS(BOB_PTR bob1, // Pointer to first BOB
BOB_PTR bob2); // Pointer to second BOB
The function returns TRUE is the two bounding rectangles overlap.
So i have tried to make for loop to check whenever the ball BOB hits the box[28] BOB, but my machine hanged....
I have also tried to do it manually like this
PHP Code:
if(Collision_BOBS(&ball, &box[1])){
......
}
etc.....
Hanged again....anyone have any ideas....my main game loop look like this:
PHP Code:
int Game_Main(void *parms)
{
// check of user is trying to exit
if (KEY_DOWN(VK_ESCAPE))
PostMessage(main_window_handle, WM_DESTROY,0,0);
if (KEY_DOWN(VK_LEFT)) {
if (paddle.x >5) {
paddle.x = paddle.x -10;
Move_BOB(&paddle);
}
} else if(KEY_DOWN(VK_RIGHT)) {
if(paddle.x + paddle.width < SCREEN_WIDTH) {
paddle.x = paddle.x +10;
Move_BOB(&paddle);
}
}
// start the timing clock
Start_Clock();
// clear the drawing surface
DD_Fill_Surface(lpddsback, 0);
Draw_BOB(&paddle,lpddsback);
Draw_BOB(&ball,lpddsback);
for (int draw = 0; draw<28; draw++)
Draw_BOB(&box[draw],lpddsback);
oh typo...but it still doesn't do it right, because when I test for collision, the game might be testing block 5 and the has just hit block 20......thats my problem....
You need to step through your code line by line, and find out EXACTLY where it crashes. From what I can see above, the problem may be in your Collision function.
The Collision function works just fine, but I was trying to step through the code using a loop but it didn't work because when the loop what testing block 5 I might hit block 26 with ball, and it also crashes.....any suggestions...
The loop I was using:
PHP Code:
for(int counter; counter<27; counter++)
if(Collision_BOBS(&ball,&box[counter])){
......//Do whatever with the block
}