Results 1 to 10 of 10

Thread: Collision Detection

Threaded View

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Collision Detection

    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:
    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_handleWM_DESTROY,0,0);
    if (
    KEY_DOWN(VK_LEFT)) {
        if (
    paddle.>5) {
            
    paddle.paddle.-10;
            
    Move_BOB(&paddle);
        }
    } else if(
    KEY_DOWN(VK_RIGHT)) {
        if(
    paddle.paddle.width  SCREEN_WIDTH) {
            
    paddle.paddle.+10;
            
    Move_BOB(&paddle);
        }
    }

    // start the timing clock
    Start_Clock();

    // clear the drawing surface
    DD_Fill_Surface(lpddsback0);

    Draw_BOB(&paddle,lpddsback);
    Draw_BOB(&ball,lpddsback);
    for (
    int draw 0draw<28draw++)
    Draw_BOB(&box[draw],lpddsback);

    ball.xv xangle;
    ball.yv yangle;
    Move_BOB(&ball);

    //the ball has gone outside the screen
    if(ball.<= ball.>= SCREEN_WIDTH ball.width ){
        
    xangle = -xangle;
    }
    // the ball has gone outside the screen
    if(ball.<= |ball.== 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 
    please let me know if you need more source code...
    Thanks in advance!
    Last edited by CyberCarsten; Nov 10th, 2002 at 04:13 PM.
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width