Skip to main content

2D Platforms

Submitted by Triton on
Forum

I've finally managed to attempt my first game and i've been fiddling around over the last few days with an api called sdl[url]http://www.libsdl.org[/url]. I've managed to get sprites working and a scrolling background, also some basic collision with bmp's. However i've run into a problem with making a level, i can't think of a good way to get a 'ground' surface. I can get a big long bmp along the bottom to work, and also place little bmp's around the screen, but this makes level design dreadful. I was wondering if it's possible to do some sort of colour collision within a bmp, i can set a transparency colour so i figured it would be something to do with that? If anyone has used sdl before and knows how to help or any other solution, it would be appreciated.
~thanks [:D]

Submitted by CombatWombat on Wed, 30/06/04 - 6:31 PM Permalink

It sounds like you're working out your collisions through looking at the actual pixel data of the bitmaps. Reading between the lines I think you're using bitmaps to render and represent the platforms?

What I'd suggest is making 3 tiles for each platform - the left end, "middle" and the right end. These should all tile together ok - then you can define your platforms as being a line in space, and render the end tiles and as many middle tiles as you need to complete the line.

So instead of using bitmaps, you're doing rectangle calculations for collisions, which are much much faster.

You could extend this tile scheme to do your ground too - so that there's water along the ground in parts, then sand, then grass etc - you can do some nice transition tiles to link between the different terrain.

A quick hacky way to do your level design then might be having a text file that had various characters representing the tiles:

[code]

%%%%%%%%

**** ***** ******* *********

###############&&&&&&&&&&&&&&&&##############-----------#############
[/code]

Where say % = clouds, * = steel mesh catwalk # = grass & = water - = ice

And you could do nifty things like make your character slide on the ice, and do a swimming animation through the water etc.

Cheers,

Mark/CW

Posted by Triton on
Forum

I've finally managed to attempt my first game and i've been fiddling around over the last few days with an api called sdl[url]http://www.libsdl.org[/url]. I've managed to get sprites working and a scrolling background, also some basic collision with bmp's. However i've run into a problem with making a level, i can't think of a good way to get a 'ground' surface. I can get a big long bmp along the bottom to work, and also place little bmp's around the screen, but this makes level design dreadful. I was wondering if it's possible to do some sort of colour collision within a bmp, i can set a transparency colour so i figured it would be something to do with that? If anyone has used sdl before and knows how to help or any other solution, it would be appreciated.
~thanks [:D]


Submitted by CombatWombat on Wed, 30/06/04 - 6:31 PM Permalink

It sounds like you're working out your collisions through looking at the actual pixel data of the bitmaps. Reading between the lines I think you're using bitmaps to render and represent the platforms?

What I'd suggest is making 3 tiles for each platform - the left end, "middle" and the right end. These should all tile together ok - then you can define your platforms as being a line in space, and render the end tiles and as many middle tiles as you need to complete the line.

So instead of using bitmaps, you're doing rectangle calculations for collisions, which are much much faster.

You could extend this tile scheme to do your ground too - so that there's water along the ground in parts, then sand, then grass etc - you can do some nice transition tiles to link between the different terrain.

A quick hacky way to do your level design then might be having a text file that had various characters representing the tiles:

[code]

%%%%%%%%

**** ***** ******* *********

###############&&&&&&&&&&&&&&&&##############-----------#############
[/code]

Where say % = clouds, * = steel mesh catwalk # = grass & = water - = ice

And you could do nifty things like make your character slide on the ice, and do a swimming animation through the water etc.

Cheers,

Mark/CW