Thread: Breakout althorigm help!!!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200

    Breakout algorithm help!!!

    In a breakout game, the simplest way to determine if the ball hits the block is define the coordinates of the block, and when the ball is in the specific coordinate, the ball hits the block. The ball direction will be invert by positive/ negative 'speed'.
    ex: if(hit==true)
    speed *= -1;

    But what if the ball is go straight into a corner of the block, what direction would the ball head to??? I've been dealing with this matter for like a week already and still haven't figure out. The speed of the ball also relative to the coordinate of the place where collision occur. The speed is faster, the colliding areas must be bigger.

    when i want to determine if the ball only hit the left side of the block. I would create a bounding box around the left side of the block. Let just say "block.x" and "block.y" are the top-left of the block. "Ball.x" and "Ball.y" are the center of the ball, the ball has a radius of 10. Block's length is 30, width is 15.
    Code:
    if( (Ball.x+10 >= block.x-1) && (Ball.x <= block.x-11))
    {
        if( (Ball.y+10 <= block.y+25) && (Ball.y-10 >= block.y))
                return NormalLeft;
    }
    The code works at certain point but it always goes wrong when it's near the corner.

    So can anyone point out how can i fix this problem. By the way, i don't use the "invert speed" way to change the direction of the ball, but actually calculate the ball's angle with the blocks' normal.
    Last edited by hdragon; 02-20-2006 at 07:26 PM.
    Hello, testing testing. Everthing is running perfectly...for now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Breakout Collision Detection Algorithm Help
    By xmltorrent in forum Game Programming
    Replies: 8
    Last Post: 08-24-2006, 02:32 PM
  2. Reference to making breakout game
    By Raison in forum Game Programming
    Replies: 10
    Last Post: 12-31-2004, 05:18 PM
  3. Turman-Nate (BreakOut Clone) 0.01
    By cMADsc in forum Game Programming
    Replies: 5
    Last Post: 04-27-2003, 02:46 PM
  4. breakout collision
    By lambs4 in forum Game Programming
    Replies: 5
    Last Post: 03-13-2003, 03:23 PM
  5. Best breakout clone ever made.
    By funkydude9 in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-15-2002, 10:25 PM