ShackRPG: Updated Tile Engine Part 1
Over the past few days, I’ve been re-working my Tile Engine and Map Editor, and before I post on it I would like to say that it has been quite a bit bigger than I had anticipated. For that reason, this post will be broken up into several posts to show the basic features of the various components of the Tile Engine / Map Editor, but without having one big 30 page post on the whole sha-bang.
So on that note, we’ll start with the Map.cs file. This file will hold all of the map information, which is actually quite a bit of data. Some of the data fields include:
string Name – Map Name
int Height – Map Height
int Width – Map Width
int TileHeight – Height of each tile on map
int TileWidth – Width of each tile on map
string Tileset – Tileset used to draw the map
Point PlayerRespawnTile – Players respawn Location
List Tiles – List of textures used for map tiles
List NPCs – List of all NPCs on the current map
List Items – List of all world-items on current map (IE: Treasures)
List Portals – List of all portals leading to OTHER maps
string MusicCue – Music data to be used on map
int[,] BaseLayer – Base Layer Layout (Things you walk on top of, grass etc)
int[,] FringeLayer – Foreground Layers layout (Things you can walk behind)
int[,] ObjectLayer – Object Layers Layout (pots, barrels, plants, etc)
int[,] CollisionLayer – Collision Layer (Tiles you can not walk on)
This is most of the information needed to make a map work with this tile engine. The next step in getting the Map.cs file in order, was a way to Save, Load, and Initialize a map. Obviously for a complex role playing game, you’ll want to have several maps. Maybe a few towns, dungeons, an overworld map, city at sea, a sky level… The choices are limitless, but for every region you have in your game, you’ll have a map to hold the information. All of these maps will hold the same structure which makes it easy for the game to load and display
I really did not want to write my own content importer / content reader in the XNA engine, so I’ve stuck with the System.XML namespace. Because of this, each map will be stored in its own XML file and fed through the XNA content pipeline, but with the map.xml property set to “Do Not Compile.”
Below is a screenshot of a test map I did while testing the map engine showing off some of the map editor.
Red P = Player Respawn
Blue P = Portal to a different map
I = Item
M = NPC / Monster
The map name is called “Map001” and you can see the XML file HERE
Not too many problems came up while working with the Map.cs file, more-so when trying to get the editor up and running.. but I’ll save that writeup for another time. Could this map file be smaller? Probably. As it stands now, it is just under 1300 lines of code. There are also several other systems needed to display the map to screen, but for anyone interested in writing their own map engine in XNA, I figured the best place to start was the map itself.
Next time I’ll go more in depth on the Tile Engine, and some of the Map Editor.