Generating our maps

I’ll talk about how we manage to create maps in our game Green Warden in a way so our designer understand how to write new maps and send them as textfiles to us programmers to implement in th game.

I encouraged our designer to use the free-to-download program Tiled (http://www.mapeditor.org/) to create new maps. With Tiled it’s possible to save what you do as textfiles. We’re using these textfiles to load different maps. In this way our designer doesn’t have to know programming to know how to create all the maps in the game.

Tiled

This is how it looks like in Tiled. In this example the green tiles represent trees, blue is water. The yellow tile is the ”Life Tree”, the player must defend that. Pink is player spawnpoint and reds are enemy spawnpoints. Grey tiles are ”empty”-tiles which are nothing but background.

Tiled_txt

When projects in Tiled are saved as textfiles you get something like this above ^. Every tile is seperated with commas where, in this case, ‘1’s are trees, ‘2’s are water tiles, ‘3’s is the Life Tree, ‘4’ for player spawnpoint and ‘5’ for enemyspawnpoints… Zeros is the empty tiles as you may have guessed already.

Now its all about translating this gibberish to a map in our game.

In our gamestate, which is prabably no exception from what most games has, we have a function called LoadMap(”[file name here]”). At the beginning of the gamestate we call this function with a specific filename, example ”assets/maps/map_42.txt”. Inside the function, this happens, explained in pseudo-style:

– function LoadMap(‘filename’)

–             Open file: ‘filename’

            while opened file is not at the end

–                               stream file-data to ‘temp_variable’

–                               switch (‘temp_variable’)

–                                              case ‘1’: new Tree; break;

–                                              case ‘2’: new Water; break;

–                                              case ‘3’: new LifeTree; break;

–                                              case ‘4’: new Player; break;

–                                              case ‘5’: new EnemySpawnpoint; break;

–                                              case ‘0’: break;

… and so it goes in the loop till the filestreamer reached the end of the file. Note, pseudocode experts, I’ve never done pseudocode before. Let’s say this is my own version to do it ;P

When each object is ”newed”, our Tilemap-class is in charge of the positions of each tile, so basically, the whole textfile could have been written in just one line and still have each tile-object positioned in the right place. It just depends on the order of each number. The Tilemap-class is just basically a grid of specific number of sqaures on the screen.

Generated map

(Note: this is not the same map as the examples above)

Right now there’s no water-tiles. Those are on its way. The tricky part there is to make them dynamicly change shape depending if multiple water-tiles are linked to each other. That work is saved for later. Beta versions supposed to be completed next friday, so there’s a lot of other stuff that has to prioritized.

I hope this read gave you some idea we do to generate our maps. Please comment if you feel there’s too little technical explanations, like snippets from the code and etc.

/Johannes W

En reaktion på ”Generating our maps

  1. This is a good blog post. I can clearly read what you have been working whit. It’s interesting to see someone using another program to create their maps. So far people seem to write the text files themselves and we were no different. And that was some work for our designer to write tile maps only by numbers. And the program you have been using seems to be a lot easier to use. A thing I’m wondering about is why you chose to load your map inside Gamestate when you could have a specific class to do this.

    Other than that the pseudo code is good at describing how you read from your text file. But then again I’m a programmer so I don’t know how much my words weigh for designer. Something I have been wondering about is did you personally write the code about this? It seems you’re not specific by whom the code has been written. This post is however valuable as it shows other ways you can create maps that can be easier to use by people that’s not programmers.

    Improvements is probably to be more specific what you have been doing in your blogpost. As your post is now I’m not entirely sure what you have been working on. But nevertheless and I’m looking forward to reading your other post and seeing how your game develops.

    Good job.

    Gilla

Lämna en kommentar