Game Development Reference
In-Depth Information
TileMap tileMap = new TileMap();
double currentX = startX;
double currentY = startY;
int xPosition = 0;
int yPosition = 0;
foreach (char c in levelDef)
{
if (c == '\n')
{
xPosition = 0;
yPosition = yPosition + 1;
currentX = startX;
currentY -= tileWidthHeight;
continue;
}
Tile t = tileLookUp[c].CreateTile();
t.SetPosition(currentX, currentY);
tileMap.AddTile(xPosition, yPosition, t);
xPosition++;
currentX += tileWidthHeight;
}
The text-based tile definition is iterated through, and each character is trans-
formed into a tile. Each tile is a type of sprite and is carefully positioned so it is
flush with its neighboring tile. ASCII characters are used to index a dictionary
that contains a set of tile definitions containing tile data. This tile data will
probably contain a texture; it will also have some flags that determine if the
player can walk on the tile, and it may have some special properties such as
ending the game when the player steps on it. The tile definition is used to create a
tile, which uses a sprite to draw itself. Once the tile is created, it's positioned and
added to the tilemap. In the game loop, the tilemap is used to render all the tiles.
The player is rendered after the tiles and is free to walk around.
A common feature for tile-based games is to layer the tiles. Several tilemaps are
created and laid on top of each other. This can be used to provide a parallax
effect, where the background moves slowly compared to the progress of the
player. It also allows the player to pass behind certain elements on the map.
3D Role-Playing Games
There is a wide variety of ways to make a 3D role-playing games, Fallout 3,
Oblivion, and Bioshock use an FPS approach. Other 3D games emulate the more
 
Search WWH ::




Custom Search