Sign in to follow this  
Butterman

Worms Style Collision Map

Recommended Posts

Hey I'm expanding the collision system on my sidescroller, i want to do a Worms style collision system on top of my tile map, so that each 'pixel' can be solid, causing the players bounding box to collide with it. Basically, i want to keep the tile based system for graphics, but put a more complicated system in for collision detection. So how would i go about doing this. I would use the editor i have in place, to modify this map, with a brush tool, to turn pixels solid. Cheers.

Share this post


Link to post
Share on other sites
Well assuming the background is 1 large image, you could easily just create a black&white image map for collision, at runtime.

Should be easy enough, and dynamic, if you wish to blow away terrain, worms style ;)

Share this post


Link to post
Share on other sites
You could check the pixel's color and if it's a certain color (let's say black) then it is considered solid. I did that for a small platformer, created the background in paint and made any 'solid' surface black. Then when the character walks up to an area colored black you just check the pixel color and if it's black don't allow him to walk there.

Share this post


Link to post
Share on other sites
Simple enough mate,

You need to have read access to your collision bitmap, and read access to the ships collision bitmap. Like above mentioned you use bit on collision, bit off no collision. So using a bit testing approach its easy to tell if there is collision at any particular pixel.

To do this locate where in your collision map the player ship is, then iterate over all the ship collision pixels versus the corresponding pixels in the collision map. Do not test against the entire map. You can pull the bits out of the collision map using your already in place tile system.

You will be working in two spaces. Local ship collision map space and world collision map space. Use the same idea as your dynamic objects in the tiled scene to find the correct location in the world collision map...

Sounds like you can do all this if you have an editor and what not up and running... For clarity you can see its all very similar to your tile system, except each bit is treated like a tile


// 2D collision area in world space
world.min.x = ship.pos.x - ship.extents.x;
world.max.x = ship.pos.x + ship.extents.x;
world.min.y = ship.pos.y - ship.extents.y;
world.max.y = ship.pos.y + ship.extents.y;

// Ship collision in local space
ship.x = 0;
ship.y = 0;

for (int y = world.min.y; y<world.max.y; ++y)
{
for (int x = world.min.x; x<world.max.x; ++x)
{
if (GetBit(world, x, y) == true && GetBit(ship, ship.x, ship.y) == true)
{
// Collides!!
}
ship.x++;
}
ship.y++;
}

// No collision


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this