# Thread: collision detect - compare player's coords to...?

1. ## 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. 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.

3. Hi,,

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

4. thanks! that was just the little push i needed... my character no longer walks through walls