Hi all...
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:
The function returns TRUE is the two bounding rectangles overlap.PHP Code:int Collision_BOBS(BOB_PTR bob1, // Pointer to first BOB
BOB_PTR bob2); // Pointer to second BOB
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
etc.....PHP Code:if(Collision_BOBS(&ball, &box[1])){
......
}
Hanged again....anyone have any ideas....my main game loop look like this:
please let me know if you need more source code...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);
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
//the ball has gone outside the screen
if(ball.x <= 0 | ball.x >= SCREEN_WIDTH - ball.width ){
xangle = -xangle;
}
// the ball has gone outside the screen
if(ball.y <= 0 |ball.y == SCREEN_HEIGHT - ball.height){
yangle = -yangle;
}
// the ball has hit the paddle
if(Collision_BOBS(&ball,&paddle)){
yangle=-yangle; // change direction
}
// flip the surfaces
DD_Flip();
// sync to 30ish fps
Wait_Clock(30);
// return success
return(1);
} // end Game_Main
Thanks in advance!![]()




Reply With Quote