Level design for a 2d platformer

Started by
0 comments, last by henthoven 20 years, 6 months ago
Hi, Currently I am writing a 2d platform game (like mario / sonic). It goed verry well, but I think I am not doing everything really efficient. The main thing is the level design. At this moment I make a level using a 2 dimensional array of integers. So a (verry small) level could look like this: int level[5][5] = { {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,1}, {0,0,0,1,1}, {1,1,1,1,1} }; Next to this level design I have a standard block width and height. So when, for example the main character, enters an x,y position I check the array at position level[y/block_height][x/block_width]. In this way I can say if it is 1 then stop, if it is 0 move on. In this example I only use 0 and 1 but of course you can imagine that a lot of other blocks (bonuses, keys etc) can be added to a level. Because I have to calculate the array position every time and check what kind of block it is, I think this can be done a lot better (or is this a good way?). Next to that it is not very handy to design a level in this way. Has anyone an idea how to do this better? Thanks in advance! Regards, Hans.
Advertisement
Calculating the array position every time, and checking the array for collisions, is a very trivial thing to do, so don''t worry too much about performance issues there. One of the rules of optimization is to only optimize where it will do you some good. In your case, you are only doing 2 divisions per collision check, so trying to optimize that would only turn ugly or confusing without any noticeable benefit.

A quick and dirty way of editing larger levels when you don''t have a dedicated, custom-written level editor is to use a simple paint program such as Paintshop Pro, and create the level as a bitmap. If you use a palletized 8-bit or greyscale 8-bit bitmap, you can have up to 256 different types of blocks, one for each color. If your paint program saves to .RAW format, you can save as raw level data; otherwise, just save and load as a BMP, translating color index to block type to fill your level array.

Good luck.

Josh
vertexnormal AT linuxmail DOT org

Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.

This topic is closed to new replies.

Advertisement