Archived

This topic is now archived and is closed to further replies.

Goblin

Tile-Based Collision Detection

Recommended Posts

I have a question. Say I have a 2D tile-based game in which the tiles are 32x32, and I want to allow parts of the tiles to be collidable, and parts not to be. So I''d compile a "monochromatic" collision map for the game in which 0 means passable and 1 means nonpassable. So one tile would be 32 DWORDs, so that it would be 32 rows of 32 bits which could be 0 or 1. How, though, would I compile this into a larger, memory-efficient, collision map, and what binary operations would I use to figure out if a player could move in a direction or not? Could this be done with any speed? Is there another way that''s much better? Thanks, ----------------- The Goblin (madgob@aol.com) ----------------- "Before critisizing somebody, walk a mile in their shoes. That way, when you do critisize them, not only will you be a mile away, but you''ll also have their shoes!"

Share this post


Link to post
Share on other sites
1.about memory, simple keep the collision map along with tile pictures. Collision map is just 32bytes while a tile picture is 32x32bytes (*bpp) so it takes a fairly small amount of mem comparing to the picture.
2.when you want to check for collisions, a simple AND instruction will do. It works like this:
if (A and B)>0 - collision
else -no collision
In case two objects aren''t exactly on the same place and/or have different size you need to do some bit-shifting etc to get it right...

all you have to do is to create a similar collision map for player to know where he can go (or you take the player as 1 point and check only this point on tile collision map, no and needed then as you simple check if this bit is 1 or 0)
Hope it helps

With best regards,
Mirek Czerwiñski
http://kris.top.pl/~kherin/

Share this post


Link to post
Share on other sites
HI I have an easier way to do 2dtile collision.You can check out the post I made to help some one at forum section GAME PROGRAMMING post 2D COLLISION.You can still use the way you are going but you would need to read the monochrome map pixels that are visible on the screen then see the value that comes back either 0 or 1 then do your collision detection return code for that. The only thing about that is I think it might be slow so I would try to write a routine in assembly.If all fails just used the way I posted at the above section.

Share this post


Link to post
Share on other sites