Closed Thread
Results 1 to 5 of 5

Thread: Collision Detection

  1. #1
    Flezria is offline Learning Programmer
    Join Date
    Sep 2009
    Posts
    55
    Rep Power
    0

    Collision Detection

    Hello guyse, i really dont understand collision detection, and i want it for my game. Anyone can tell me how to add a collision detection(just easy one) so you cant walk through walls.

    Thanks from flezria

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Collision Detection

    2D? 3D? Sprite based? Other?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Flezria is offline Learning Programmer
    Join Date
    Sep 2009
    Posts
    55
    Rep Power
    0

    Re: Collision Detection

    Its in 2d, its going to be a space invaders game, when its done.

  5. #4
    CallinWire's Avatar
    CallinWire is offline Newbie
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Re: Collision Detection

    Just think of your sprites as rectangles. Each one will have a top, left, right, and bottom edges. Get the x or y coordinate value of each edge (assuming values get larger as you go down or right) , then compare them to see if they intersect:

    Code:
    // if the top edge of one sprite is below the bottom edge 
    // of the other, then no collision occurs. 
    // do the same for the other four edges
    if (sprite1.topEdge < sprite2.bottomEdge) return false;
    
    if (sprite1.bottomEdge > sprite2.topEdge) return false;
    if (sprite1.leftEdge > sprite2.rightEdge) return false;
    if (sprite1.rightEdge < sprite2.leftEdge) return false;
    return true; // otherwise, they must have collided

  6. #5
    Flezria is offline Learning Programmer
    Join Date
    Sep 2009
    Posts
    55
    Rep Power
    0

    Re: Collision Detection

    Thanks alot for the help, ill take a look on it

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Double buffering, movement, and collision detection.
    By farrell2k in forum Java Tutorials
    Replies: 16
    Last Post: 01-24-2012, 10:56 PM
  2. Intermediate Pixel Perfect Collision Detection (USE FOR YOUR JAVA GAMES!)
    By TrolliOlli in forum Java Tutorials
    Replies: 2
    Last Post: 10-11-2011, 12:48 AM
  3. Pacman Collision detection 2D array
    By jannemoon in forum C# Programming
    Replies: 0
    Last Post: 03-06-2011, 07:28 AM
  4. collision detection in pygame
    By BRUTAL in forum Python
    Replies: 3
    Last Post: 02-05-2011, 11:26 PM
  5. Collision Detection
    By cocoa10 in forum C and C++
    Replies: 8
    Last Post: 10-26-2010, 09:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

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