2d overhead tiling "engine"

Started by
1 comment, last by Gabriel Marincu 11 years, 8 months ago
Hello gamedev.

This being my first post i'd like to first introduce myself.My name is Gabriel and I am 16 years old.

I've always had a great hunger for 2d adventure games.By this age I've played more than I could count (metaphorically speaking).

Now that my highschool has introduced me to programming I am baffled by the idea that I could make my own 2d adventure game.
Now with the formalities done I'd like to get to it.
I am quite confortable in the C++ language (doing it in school for 1 year plus my home learning), up to the point of classes and structures (I can implement something using these concepts but it doesn't come as natural as the other features of the language do), but my real experience in developing games comes with the Python programming language along with the SDL spinoff Pygame.

I dived in the Pygame documentation and learned all the functions and methods I deemed necessary for my game and shortly after that I started working on my first game: a Space Invaders clone. It turned out quite nice and it surely was a playable game but my dream is a overhead adventure game.

I know that for this type of game tile engines are the most widespread because of flexibility and memory conservation, so i set out on the stupendous journey of designing my own tile engine but as I advanced with the engine it simply became too overwhelming.Finally i managed to put together a simple,clean (this is a big lie), 1 layer engine that could load, display,and save levels quite nicely.

I now see how childish I was when i made my tile engine.My code seemed now like a zombie with only duct tape holding it in part.

Now I am sorry to have bored you with the stupidly long story but I have one thing to ask:

Can you please point me in the direction of basic multi layered tile engine making (not i am not asking for code snippets)?

Just the logical steps of designing a multi layered tile engine. (links to tutorials, some pseudocode-ish ideas would be a bonus)

Thank you!
PS:Excuse my english please...
Advertisement
A simple way to load tiles and maps:
Have a file that lists each tile image, or have a large tilesheet, and make each tile be represented by an number ("[color=#008000]../tiles/floors/grass/grass17.png" == id [color=#008080]'543').

Have a map with, say, 5 layers of 100 by 100 tiles. ([size=2]When learning something, I like to use fixed amounts like '5 layers' or '100 by 100 tiles', and once I understand it, then I make it capable of handling any amount of layers and any amount of tiles).

Have your map file store each layer as 100 by 100 integers, using the ID of each tile ([color=#008080]'543' for [color=#008000]'grass17.png'), instead of the tile itself.
It'll look something like this:
543 342 468 343 123 1072 ...
343 123 108 514 342 468 ...
54 514 342 468 123 1072 ...

But 100 by 100. You can make the saved file comma separated, or space separated or whatever you like.

When your game starts, load all the tile images into an array. When drawing your map, for each tile [color=#008080]ID in the map, use that ID to find the tile image in the array and draw that. If you use the [color=#008000]grass17.png a hundred times in one map, you should still only have one copy of the image that you loaded once, and just used the same image to draw each of the hundred grass tiles in the map.

[hr]

When drawing a tile map, you can go like this:

array Layer = array of 100 x 100 integers [color=#008080](tile IDs)
array Map = array of 5 Layers
Map myMap = load_map();
array tileImages = array of loaded images

for each layer in myMap:
for each row in layer:
for each column in row:
tileID = myMap[layer]->[row][column];
xPos = column * TILE_WIDTH;
yPos = row * TILE_HEIGHT;
draw_image(tileImages[tileID], draw at: xPos, yPos);


This is a simple way of doing things. Once you understand that, there are improvements you can make, such as: loading the images not at startup, but only when needed. Freeing the images that aren't needed. Saving images when changing maps if both maps use the same image. Any number of layers. Any size of maps. Breaking large maps into smaller chunks of maps, and only loading the chunks that are currently visible.

PS: Your English is quite good. wink.png
Thank you for the great explanation!
I've applied an extremely similar principle but I complicated myself by using a Map class instead of just an array.
The layer concept was a bit cloudy in my head but now you cleared it up.
Thanks again!

This topic is closed to new replies.

Advertisement