Jump to content

  • Log In with Google      Sign In   
  • Create Account

how to write a game like worm reloaded


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 tracegame   Members   -  Reputation: 134

Like
0Likes
Like

Posted 24 June 2012 - 04:57 AM

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?

Sponsor:

#2 szecs   Members   -  Reputation: 2185

Like
0Likes
Like

Posted 24 June 2012 - 06:42 AM

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:

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

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, 24 June 2012 - 06:43 AM.


#3 BeerNutts   Crossbones+   -  Reputation: 2999

Like
0Likes
Like

Posted 24 June 2012 - 09:00 PM

Look into a 2d physics engine. I use chipmunk-physics, but others use box2d. Google 'em
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#4 speciesUnknown   Members   -  Reputation: 527

Like
1Likes
Like

Posted 25 June 2012 - 06:04 AM

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.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!

#5 BeerNutts   Crossbones+   -  Reputation: 2999

Like
0Likes
Like

Posted 25 June 2012 - 07:35 AM


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.


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.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#6 speciesUnknown   Members   -  Reputation: 527

Like
0Likes
Like

Posted 25 June 2012 - 08:06 AM



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.


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.


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, 25 June 2012 - 08:09 AM.

Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!

#7 szecs   Members   -  Reputation: 2185

Like
0Likes
Like

Posted 25 June 2012 - 08:34 AM

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.

#8 tracegame   Members   -  Reputation: 134

Like
0Likes
Like

Posted 26 June 2012 - 04:31 AM

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, 26 June 2012 - 05:01 AM.


#9 6677   Members   -  Reputation: 1058

Like
0Likes
Like

Posted 26 June 2012 - 11:36 AM

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.

#10 AverageJoeSSU   Members   -  Reputation: 516

Like
0Likes
Like

Posted 26 June 2012 - 04:22 PM

http://www.emanueleferonato.com/2012/05/24/the-guide-to-implementing-2d-platformers/

scroll down to the bitmask section

------------------------------

redwoodpixel.com





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS