Choosing A Level Format


chris_r

Active Member
Joined
Jun 16, 2004
Messages
745
I'm (attempting to) code a platformer, hopefully in time for the pandora release. My coding experience is limited so I need a bit of advice.

So far I have a character (just a rectangle at the moment) that you can move left and right, some primitive jumping and rectangle collision detection.

What I need to design now is a format for storing and computing the levels, I can think of 2 ways but I don't know which would be better and thought i'd get some advice before starting.


My first idea is the obvious tilemap design. This obviously gives the game a very retro feel and all the tiles are the same size etc. But this does make collision detection a lot easier.

My second idea was having a background image and then rectangle dimensions/placements stored in a file.
The image would be displayed and the rectangles would define the places where the character collides (walls, platforms etc.)


Taking into consideration things like memory requirements/processor speed/ease of programming (remember I am not too experienced) what would you recommend as the best idea for the level format.
Alternatively if there is a better way to do this, I would also like to hear about that.
 
I'd say that the tilemap is the way to go. It will run faster and be a lot easier to maintain and design levels with. Storing all the collisions and placements in a separate file may seem like a more flexible method, but I think it would end up getting messy and tedious - besides, tiles don't all have to have the same visual dimensions and properties. Think of the Sonic games, they're tile based yet they have all kinds of crazy ramps and loops, all thanks to a flexible tile engine :) You could have an array of tile properties, like slope steepness, walkable width, etc., all quickly accessible through each tile's index number.

Have fun :)
 
I never knew sonic was tile based. That's quite interesting. And I never thought about that array idea. It shouldn't be too difficult to code in different behaviours for tiles.
Thanks for that.

Anyone else got any input?
 
Sonic was actually even more complex--the levels were made of larger pieces like 16x16 groups of tiles that could be repeated several times, and that's how it has huge levels with similar complicated areas (ie loops) and still saves a lot of memory :)
 
chris_r said:
I never knew sonic was tile based. That's quite interesting. And I never thought about that array idea. It shouldn't be too difficult to code in different behaviours for tiles.
Thanks for that.

Anyone else got any input?
Tilemap is definitely the way to go, it goes hand in hand with platform games. It's a good way to keep the size of the game to a minimum (filesize, not length!) and also depending on implementation, could use significantly less RAM than using a background. This is good because it means you have more RAM available so you can create larger levels! :)
 
Last edited by a moderator:
Ok so if I use a tile engine for the level design, is there a good way to implement items/enemies into that or should they just be defined separately with their own co-ordinates?

Edit: For reference my tilemap will not be much more complicated that is shown in lazyfoo's tutorial.
http://lazyfoo.net/SDL_tutorials/lesson29/index.php
 
Tiles defiantly. I tryed to create a game with collision data stored in a separate file, it was a PITA trying to align everything with the image background. in the end i rewrote the whole thing using a tile based engine, then lost interest in the project :(

QUOTE
Ok so if I use a tile engine for the level design, is there a good way to implement items/enemies into that or should they just be defined separately with their own co-ordinates?

personally I used an array of ints for storing the level data, and different numbers refer to a background and 'sub object'. for instance, 5 may be a walkable tile, but 6 may be the same tile as 5, with the addition of a crusher.

http://www.vimeo.com/1264043
 
Usually enemies and movable things are defined separately, because they are, well, movable and might come in different sizes, have different functionality, etc. But nothing prevents you to set their initial positions to tiles positions in the map :)
 
You could have tiles indicating an enemy's starting position, and when that specific tile is on-screen, you take the enemy indicator off the tile, and add the enemy to a list of active enemies. When the enemy dies, you take it out of the activelist, and when it goes off-screen you add the tile indicator back, and remove the enemy from the active list. Now I want to code a platformer too :D
 
Hessiess said:
personally I used an array of ints for storing the level data, and different numbers refer to a background and 'sub object'. for instance, 5 may be a walkable tile, but 6 may be the same tile as 5, with the addition of a crusher.

Why not use a Bitfield per tile where each represents an attribute? For example, the first bit represents if it walkable or not, the fifth would represent the crusher.
 
Last edited by a moderator:
yaustar said:
Hessiess said:
personally I used an array of ints for storing the level data, and different numbers refer to a background and 'sub object'. for instance, 5 may be a walkable tile, but 6 may be the same tile as 5, with the addition of a crusher.

Why not use a Bitfield per tile where each represents an attribute? For example, the first bit represents if it walkable or not, the fifth would represent the crusher.
Setting the boolean types with #define macros might be better or an array of bitsets. Bitfields, when stored in a binary file, are even worse than endian swapped literals in regards to portability. They will vary not only by byte ordering but by bit ordering within the bytes and they vary not only by processor and operating system but from one compiler to the next. :p
 
Last edited by a moderator:
hey

Ya might also wanna checkout http://www.nonoche.com/imaging/en/index.html.

Hmm, also when it comes to making the levels you could either make ya own little tilemap editor, or you could make an image converter where it searches for all unique tiles and builds map with indices to each tile and what not.

I have done both, I like the second option because you can easily pixel and add new tiles to ya maps, but with the first option it's faster to place tiles. Hmm, well there might be image editors that allow ya to tile and such, which would be handy.

Umm, for tiles I just use a 2d array with indices to each graphic. So if you have a map made of 32x32 sized tiles and ya wanna see what tile to draw at the point(500, 40) on the screen just lookup the tile graphic index at tilemap[500/32][40/32]. I hope I make some sense.

Umm, for the little sidescroller mario demo thingy I have made I just gave the player, enemies and items their own coordinates. Although you could define a tile for them to start in, this is what I done anyhows.

cyas
 
Alex. said:
You could have tiles indicating an enemy's starting position, and when that specific tile is on-screen, you take the enemy indicator off the tile, and add the enemy to a list of active enemies. When the enemy dies, you take it out of the activelist, and when it goes off-screen you add the tile indicator back, and remove the enemy from the active list. Now I want to code a platformer too :D
Haha, I totally agree, Alex. I love reading/talking/thinking about development of tile-based games and this discussion is making me feeling like getting into it again :p
I used the approach you described in a vertical space shooter and it worked just fine. There can also be a combination of tiles and perfect pixel collision, I once started a Dizzy remake for the GP32 and even though it did not get far, Dizzy was happily walking and jumping on a tile-based landscape perfectly following its bumpy surface :) It needed a tile map, the tile gfx data and a shadow map (made out of the tile gfx data).
 
Last edited by a moderator:
yosh64 said:
hey

Ya might also wanna checkout http://www.nonoche.com/imaging/en/index.html.

Hmm, also when it comes to making the levels you could either make ya own little tilemap editor, or you could make an image converter where it searches for all unique tiles and builds map with indices to each tile and what not.

I have done both, I like the second option because you can easily pixel and add new tiles to ya maps, but with the first option it's faster to place tiles. Hmm, well there might be image editors that allow ya to tile and such, which would be handy.

Umm, for tiles I just use a 2d array with indices to each graphic. So if you have a map made of 32x32 sized tiles and ya wanna see what tile to draw at the point(500, 40) on the screen just lookup the tile graphic index at tilemap[500/32][40/32]. I hope I make some sense.

Umm, for the little sidescroller mario demo thingy I have made I just gave the player, enemies and items their own coordinates. Although you could define a tile for them to start in, this is what I done anyhows.

cyas


There's a good handful of apps specifically designed to edit tile maps :) And the yusually export to text-based formats that are easy to parse.

Actually about the bitfield stuff, you could always just keep it like that in memory but export to something portable like text or XML, and then maybe (g)zip that to save space? :)

edit: http://www.google.com/search?q=tile+editor :
- http://tilestudio.sourceforge.net/
 
Last edited by a moderator:
That tilestudio program looks quite good. I'll give that a try. At the moment I'm just coding the basic tile engine to draw the background and then I'll work on tile definitions.
After that I'll try to figure out how to get tilestudio to export into the correct format. Luckily for me I just got my hands on a tablet PC.

Thanks for the input guys.
 
What about landscape like in worms ? a byte(or two) per pixel - easily edited with any graphics editor :)
 
Back
Top