collision detect - compare player's coords to...?

This is a discussion on collision detect - compare player's coords to...? within the Game Programming forums, part of the General Programming Boards category; i seem to be popping up a lot in here lately so, this time it's about collision detection... here's what ...

  1. #1
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176

    collision detect - compare player's coords to...?

    i seem to be popping up a lot in here lately

    so, this time it's about collision detection... here's what i've got.

    i just used a text file to hold maps (for now). it's basically just a grid with x's and o's. so a map will look like this:
    Code:
    xxxxxxxxxxxxxxxxxxxx
    xoooooooooooooooooox
    xoooooooooooooooooox
    xoooooooooooooooooox
    xoooooxxooxxooooooox
    xooxxoooooooooooooox
    xoooooooooooooooooox
    xxxoooooooooooooooox
    xooooooooooooooooxxx
    xooxxoooooooooooxxxx
    xooooooooooooooxxxxx
    xxxoooooooooooxxxxxx
    xooooooooooooxxxxxxx
    xoooooooooooxxxxxxxx
    xxxxxxxxxxxxxxxxxxxx
    so i can load that, store it in all in a 2d array, and draw tiles so that it looks like that map.

    so now, how would i do some collision detection? so that i know if my little character is hitting a wall, standing on a ledge, bumping his head when jumping, etc... i assume i test the character's x and y coords against something.. but what, exactly? i searched around, but didn't really find what i was looking for...

    i really just need to know what to check the player's x/y coordinates against.. i should be able to get it from there.. i hope

    (it probably shouldn't have taken that long of a message for such a question, but i'm not very good at getting a messge across... oh well)

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Check it against the data in the 2D array. Like, if he is in cell [2,3] then you may have a function that takes two parameters ( position ) and return an int. This int will tell you something descriptive about the tile. You can use #define's to make them more intuitive. So something like

    Code:
    #define WALL 0x01
    #define TELEPORT 0x02
    This way you can do something after you find out what tile they are on OR what tile they are attempting to go to. Good luck.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Hi,,

    Also, perform the collision detection when the arrow key is pressed, so that the character would not stay in between the wall.

  4. #4
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    thanks! that was just the little push i needed... my character no longer walks through walls

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, 09:45 AM
  2. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 03:25 PM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 01:13 AM
  4. How do I detect collision?
    By Marcos in forum Game Programming
    Replies: 11
    Last Post: 03-24-2004, 03:49 PM
  5. Collision with quads?
    By SyntaxBubble in forum Game Programming
    Replies: 6
    Last Post: 01-18-2002, 06:17 PM

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