The map editor is a stand-alone client apart from the main game client. They will not be sharing any code. I have broken the map editor down into 6 classes: Main, Map, References, SaveMap, TileChooser, Ui. Most of the interface happens on the Map class, and you can probably guess what the rest is for.
Within the Map class is a 3D array called grid. This array contains the visuals of all the layers of the map; it is essentially the data of the map... So it will be what is uploaded to the games database and saved in the end of the day, and the only piece of the map editor that the real game client will ever see. Since this is a tile-based game, each tile has its own element on the grid array. grid[0][1][2] would be represent layer 0, x location 1, y location 2. The value will be an integer based on what tile is chosen for that location on the grid.
This is pretty standard stuff and can be seen on most RPG making tutorials. A similar 3D array holds the instances of each tile (the visual representation of each tile), which I call images. It is important that the array is 3D, not 2D. Obviously the game is 2D, but I want to have some layers on top of the players character and some behind. I will probably be sticking with 4 layers: Layer 0 will contain the basic background tiles (usually grass or cobblestone). Layer 1 will contain objects like bushes, houses, and doodads like tree trunks. Layer 2 will contain the player and interactive objects like NPCs or signs. Layer 3 will contain foreground objects like the top of trees. That way when the player walks behind a tree the tree stays in front of the player.
Using It
Clicking on the map goes through the tiles. So if you click on a piece of grass, it turns into a barrel. If you click on a barrel, it turns into a stone. If you click on a stone, it turns into nothing. If you click on nothing it turns into grass. There are only these three tiles. During my next expansion to the map editor, I will be adding more tiles and a new system for choosing your tile, because once there are 100+ tiles the map creator really will not want to click so many times just to find the single tile he wants.
This code takes the mapdata already retrieved from the server and adjusts it so that the grid is the correct size |
It is effective enough to make a small map, but I think I will be working on making it better before I start working on the game client.
This is version 2 of the map editor. I don't have any screenshots of version 1 saved. |
We will see an example swf that you can actually play with in the next blog post.
Lss
No comments:
Post a Comment