Jump to content

  • Log In with Google      Sign In   
  • Create Account


2d overhead tiling "engine"


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Djfix   Members   -  Reputation: 237

Like
0Likes
Like

Posted 16 August 2012 - 10:08 AM

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...

Edited by Djfix, 16 August 2012 - 10:09 AM.


Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 18242

Like
6Likes
Like

Posted 17 August 2012 - 11:32 PM

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 ("../tiles/floors/grass/grass17.png" == id '543').

Have a map with, say, 5 layers of 100 by 100 tiles. (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 ('543' for '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 ID in the map, use that ID to find the tile image in the array and draw that. If you use the 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.

 

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

array Layer = array of 100 x 100 integers [b][color=#008080](tile IDs)[/color][/b]
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. Posted Image

Edited by Servant of the Lord, 17 August 2012 - 11:33 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.

[Fly with me on Twitter] [Google+] [My broken website]

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.                                                                                                                                                            [Need web hosting? I personally like A Small Orange]
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal


#3 Djfix   Members   -  Reputation: 237

Like
1Likes
Like

Posted 19 August 2012 - 11:57 AM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS