2d game stage

Started by
9 comments, last by psychoullis 19 years, 4 months ago
hello. I am making a 2d game (worms style). I am know at the point where i have to add the stage in my game. But i really dont know how this is done and under what name to look it for. I suppose i need to import an image that will be the static stage, but how am i going to determine which regions of this image are the collision regions? Thank you.
Advertisement
I'd suggest setting up a second image of the same size with collision info. Just make it palettized and let each color represent one of the different collision types (sky, solid, water, slippery, etc..).
Oh, and don't worry about the file size. It'll compress great, I'd expect a ratio of something like a few hundred to one.
Hello and thank you for the reply.

Ok i can see what you are saying but could you plz help me a bit more? As far as i know i am doing collision check using the bounding boxes of the sprites (yes i far behind :) ).

The way you suggest is to check pixel by pixel whether they lay within the bounding box of a sprite? and then according to the color of the sprite to know how to modify the position of the sprite?

any information and suggetsions would be very helpful.

thnx
Quote:Original post by doynax
Oh, and don't worry about the file size. It'll compress great, I'd expect a ratio of something like a few hundred to one.

The file would still be huge in memory.
I'd suggest starting with seperate palletised images first - one for collision (0 = no collision, non-zero = collide) testing and (optionally) one for further type info (as donax suggested one palette index for each type).

Once you have this working you can easily convert the collision mask to a one bit image, where for each image pixel only one bit is used (bit set = collide):

// Returns if a coordinate from a bit-packed collision mask is// marked for collisioninline bool Collide(const int x, const int y) {    // bit mask for each pixel in an octet    static const int pixelMask[] = { 1, 2, 4, 8, 16, 32, 64, 128 };    int octetIndexX = x >> 3; // 8 pixels per byte    // collisionMaskPitch is image width / 8    int octet = collisionMask[y * collisionMaskPitch + octetIndexX];     // there are 8 pixels packed in one byte, select index using  a mask     return (octet & pixelMask[x & 7])) != 0;}


This provides a constant in-memory compression ratio of 1:8 for collision masks.

Good luck,
Pat.
Quote:Original post by psychoullis
The way you suggest is to check pixel by pixel whether they lay within the bounding box of a sprite? and then according to the color of the sprite to know how to modify the position of the sprite?

You can build a quad tree from your collision mask and sprites that goes down to a convinient minimal tile size (say 8x8 pixels) and perform a per-pixel test if the tile is marked as collision tile.
You can have three types of tiles:
- no collide
- partial collide (e.g. at least one pixel/sub-tile is marked as collide/partial collide)
- collide (e.g. all contained pixels/sub-tiles are marked as collide)

You only need to do a per-pixel test for partial-collide tiles then.
hmmm...
thnx guys for your help. i am still trying to figure out exactly what you are suggesting. I know nothing about this techniques. Do you have any link to somewhere to explain these collision techniques?

i would really appriciate it if you could explain it in a bit more detail.

Thank you.
Another thing you might find interesting is a span buffer, which is actually an extreme case of RLE, it compresses great (better than quadtrees), and can be accessed faster than bitfields in most cases. Modification is also easy, because "explosions" amount to removing a precalculated span (so it takes much less time).

I think there was on flipcode some time ago an article on "S-Buffers", feel free to check it out.
i looked in flipcode but i cannot fund the article you suggested. As i told you i know nothing about these techniques so any simple explanasions would get me started
There's an article here on GD about S Buffers: clicky
ouf.. that seems too complicated for me right now. Isn't there any simpler way to do it?

Thnx

This topic is closed to new replies.

Advertisement