• Advertisement
Sign in to follow this  

how to write a game like worm reloaded

This topic is 2035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

well,right now i can write some physical movement for bullet,that's easy.

but i have no idea for map collision,it seems to perform like pixel collision?maybe not,just my opition.

how can i judge my bullet collide with map?i think i can use brute force to loop my bullet shape pixel with map shape pixel every frame

but that seems too expensive.what should i do to get a nice and effective way?

Share this post


Link to post
Share on other sites
Advertisement
Depends on the platform. I'm not sure about Worms, but in most artillery games, you can do simple pixel color check. I did this for a Scorched Earth clone.

You can even have a screen size buffer, so that your collision check becomes simply this:

[font=courier new,courier,monospace]if( ScrnBuffer[x][y] != EMPTY )[/font]
[font=courier new,courier,monospace]{[/font]
[font=courier new,courier,monospace] Explosion!!![/font]
[font=courier new,courier,monospace]}[/font]

Maybe this can be another texture, and you draw to it in a different pass than the actual rendering. then you can lok up the pixel/texel's color.


Please give some more details about the platform, graphics API, etc so that we can give you better ideas. Edited by szecs

Share this post


Link to post
Share on other sites

Look into a 2d physics engine. I use chipmunk-physics, but others use box2d. Google 'em


They don't have any collision routines for a pixel map.



You can even have a screen size buffer, so that your collision check becomes simply this:

if( ScrnBuffer[x][y] != EMPTY )
{
Explosion!!!
}
...


The direct sampling approach is also no good because of tunneling. Projectiles will be on one side of a thin barrier on one frame, and the other on the next.

What you need is to cast a line into the grid, from the previous position of the projectile to its calculated next position. The point of collision is the first pixel that it hits along (the one with the smallest T value). Bresenhams line is one way to do this. Test each pixel that the line passes through until you get a hit.

http://en.wikipedia.org/wiki/Bresenham's_line_algorithm

When an explosion occurs, you can remove pixels from your pixel sized grid to damage the level. For characters walking, a ray cast downward will suffice. Let them fall through gaps of 1px (these will be rare though, if you are blowing holes in the terrain with explosions). You can do a brute force iteration over a square area that covers your circle, doing a distance-from-centre test to ensure you don't fill out the corners. Performance here is acceptable, don't try to optimise that yet.

The last thing you need to remember is to use a grid of smaller textures, don't try to do it with a single huge texture, because you have to modify textures when they get holes blown in them. Textures that stayed intact can be left unmodified. For a basic implementation, this is the only optimisation you really need.

Share this post


Link to post
Share on other sites

[quote name='BeerNutts' timestamp='1340593256' post='4952527']
Look into a 2d physics engine. I use chipmunk-physics, but others use box2d. Google 'em


They don't have any collision routines for a pixel map.



You can even have a screen size buffer, so that your collision check becomes simply this:

if( ScrnBuffer[x][y] != EMPTY )
{
Explosion!!!
}
...


The direct sampling approach is also no good because of tunneling. Projectiles will be on one side of a thin barrier on one frame, and the other on the next.

What you need is to cast a line into the grid, from the previous position of the projectile to its calculated next position. The point of collision is the first pixel that it hits along (the one with the smallest T value). Bresenhams line is one way to do this. Test each pixel that the line passes through until you get a hit.

http://en.wikipedia...._line_algorithm

When an explosion occurs, you can remove pixels from your pixel sized grid to damage the level. For characters walking, a ray cast downward will suffice. Let them fall through gaps of 1px (these will be rare though, if you are blowing holes in the terrain with explosions). You can do a brute force iteration over a square area that covers your circle, doing a distance-from-centre test to ensure you don't fill out the corners. Performance here is acceptable, don't try to optimise that yet.

The last thing you need to remember is to use a grid of smaller textures, don't try to do it with a single huge texture, because you have to modify textures when they get holes blown in them. Textures that stayed intact can be left unmodified. For a basic implementation, this is the only optimisation you really need.
[/quote]

That's correct, but you can generate the lines under the map to match almost perfectly. And, what you'll gain from the physics library is immense time and brain saving.

The implementation you suggest has many difficulties, whereas the physics engine will handle everything movable for you (walking, shooting, colliding, etc.). The main difficulty with a physics engine is handling creating the craters from explosions. But, I'd say even that can be modified via small line-segments. That's how I'd do it at least.

Share this post


Link to post
Share on other sites

[quote name='speciesUnknown' timestamp='1340625854' post='4952624']
[quote name='BeerNutts' timestamp='1340593256' post='4952527']
Look into a 2d physics engine. I use chipmunk-physics, but others use box2d. Google 'em


They don't have any collision routines for a pixel map.



You can even have a screen size buffer, so that your collision check becomes simply this:

if( ScrnBuffer[x][y] != EMPTY )
{
Explosion!!!
}
...


The direct sampling approach is also no good because of tunneling. Projectiles will be on one side of a thin barrier on one frame, and the other on the next.

What you need is to cast a line into the grid, from the previous position of the projectile to its calculated next position. The point of collision is the first pixel that it hits along (the one with the smallest T value). Bresenhams line is one way to do this. Test each pixel that the line passes through until you get a hit.

http://en.wikipedia...._line_algorithm

When an explosion occurs, you can remove pixels from your pixel sized grid to damage the level. For characters walking, a ray cast downward will suffice. Let them fall through gaps of 1px (these will be rare though, if you are blowing holes in the terrain with explosions). You can do a brute force iteration over a square area that covers your circle, doing a distance-from-centre test to ensure you don't fill out the corners. Performance here is acceptable, don't try to optimise that yet.

The last thing you need to remember is to use a grid of smaller textures, don't try to do it with a single huge texture, because you have to modify textures when they get holes blown in them. Textures that stayed intact can be left unmodified. For a basic implementation, this is the only optimisation you really need.
[/quote]

That's correct, but you can generate the lines under the map to match almost perfectly. And, what you'll gain from the physics library is immense time and brain saving.

The implementation you suggest has many difficulties, whereas the physics engine will handle everything movable for you (walking, shooting, colliding, etc.). The main difficulty with a physics engine is handling creating the craters from explosions. But, I'd say even that can be modified via small line-segments. That's how I'd do it at least.
[/quote]

Physics engines are designed to do one thing well - rigid bodies. If you don't have rigid bodies, attempting to force them to use a different paradigm is not worth the time they will save you. Box2d does not have built in character controllers, and even if it did they would be for use in a rigid body simulation. There is a fine line between sensible code resuse and trying to force a tool to do something it cannot do.

You will spend more time on your line segment hack, and making that support terrain destruction via explosions, than you will save by using the physics engine. You will still have to implement you character controller manually, and you will still need to write the projectile system yourself, to use line segment queries (if you use rigid bodies to simulate projectiles, they will tunnel) Edited by speciesUnknown

Share this post


Link to post
Share on other sites
Direct sampling is okay if you have small steps. Of course you can have more sophisticated algorithms, but I was just showing the basic idea.

A bit of context may be useful from the OP. Since small steps could be sufficient enough but could not.

Share this post


Link to post
Share on other sites
thank you,i just get the line cast idea this morning when i still in my dream i guess...but still get a problem.
this line cast can check collision only for a single pixel,i mean my bullet or say projectile has a volume,unregular shape,
like grenade,missile, sheep maybe...if i only use a line,consider a thin tunnel,i can pass the line test,but actually my
missile or sheep may be blocked by his shape.

so i think maybe i could cast three lines,one for the center,the other for the edges.just like a box.
but what if there is a nasty map just breaks my rule,which can just pass the three line test,but some small or some fuzzy area between the lines can still block my sheep....

then i have to cast more rays,do i have to?

by the way:the platform is Windows,API is DX9 or FlashPlayer11,i think they're not really different for pixel algorithm Edited by tracegame

Share this post


Link to post
Share on other sites
I believe there are techniques where you cast a line that has a thickness equal to the frontal area of the projectile, I've not tried raycasting at all before so couldn't tell you how its done.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement