Thread: breakout collision

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    breakout collision

    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--;
                    }
    			}
    		}
    	}
    Last edited by lambs4; 03-08-2003 at 10:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some collision handling fun
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 04-13-2008, 08:45 AM
  2. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 03:25 PM
  3. Breakout Collision Detection Algorithm Help
    By xmltorrent in forum Game Programming
    Replies: 8
    Last Post: 08-24-2006, 02:32 PM
  4. breakout style game collision detection
    By m00se123 in forum Game Programming
    Replies: 6
    Last Post: 10-31-2002, 09:18 AM
  5. Replies: 4
    Last Post: 05-03-2002, 09:40 PM