Collision Detection

This is a discussion on Collision Detection within the Game Programming forums, part of the General Programming Boards category; Ze engine... She's alive! Well everything thus far is just dandy, but there's something I'll need to consider later on ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Collision Detection

    Ze engine... She's alive!

    Well everything thus far is just dandy, but there's something I'll need to consider later on - collision detection.

    Can someone explain to me algorithmically how this is best done at it's simplest - I.E. in a 2D engine?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    You using vectors or sprites?

    For sprites the simplest method is bounding box collision detection. You have a box for the width and height of an object and then you go through every object checking to see if it overlaps with the one you're testing

    Code:
     
    bool overlap(Rectangle box, Rectangle test)
    {
      if (box.x + box.w > test.x && box.x < test.x + test.w && box.y + box.h > test.y && box.y < test.y + test.h)
        return true;
      else
        return false;
    }
    If you get an overlap go through every pixel of box sprite and if a pixel of box sprite is in the same position as a pixel of test sprite you have a collision.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Sprites.

    Cheers that helped a lot
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 03:25 PM
  2. Collision Detection
    By Grantyt3 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2005, 04:21 PM
  3. bounding box collision detection
    By DavidP in forum Game Programming
    Replies: 7
    Last Post: 07-08-2002, 12:43 AM
  4. collision detection
    By DavidP in forum Game Programming
    Replies: 2
    Last Post: 05-11-2002, 02:31 PM
  5. Replies: 4
    Last Post: 05-03-2002, 10:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21