Tile Map Collision Help

BlitzMax Forums/BlitzMax Programming/Tile Map Collision Help

RetroRusty(Posted 2010) [#1]
Hi,

I'm having problems working out how to do player - tile map array collisions. I just can't seem to get my head around it and wondered if there was anyone that could help me out?

I have uploaded a simple example of a game I'm working on, can someone please take a look at it and help me understand how collisions work?

You can get the code from the following link. http://www.retroreloaded.com/russ/collisionhelp.zip

I've had a go (which you will see) but didn't get very far with it. If someone has got time to look at it, can you keep it simple and try to explain what you are doing?

Last edited 2010

Last edited 2010


shinkiro1(Posted 2010) [#2]
I've looked a little bit into your code and haven't seen a collision layer.
It's a common technique to have a seperate Layer only for collisions. On this layer the values in the array are either 0 or 1. 1 means it's blocked and you can't pass.
So before you process user input, you use an if statement to verify if the value in the collision-array is 0:

right: (current_player_position_x + 1) = 0
left: (current_player_position_x - 1) = 0
up: (current_player_position_y - 1) = 0
down: (current_player_position_y + 1) = 0



In the image you see the player as the green point. In this case if the player wants to move up, he can't because there is a 1 in the collision array.
Any other direction + 1 is free (is 0) so then the player can move on.
Of course you have to set these values manually into the array, but thats easy if you have a map-editor, which you should definetly have.


Jesse(Posted 2010) [#3]
Another problem you are going to encounter is that yours and the above code example only checks one pixel against its position on the tile grid but the image is 32 pixels squre. Use a tile hit area(hit box). Check against the tilegrid with a hit box smaller than the size of the tile square. That way, it's a lot easier to fit between two tiles separated by a single tile space also check only against the two corners in the direction of travel. if you still can't figure it out, I can post the workingcode.


RetroRusty(Posted 2010) [#4]
@Jesse

I think I understand what you are getting out but I can't work out how to do it. Do you have an example so I can see how you are doing it?


Jesse(Posted 2010) [#5]



RetroRusty(Posted 2010) [#6]
@Jesse

Thanks a lot for this man, I really appreciate it.