Game Development Reference
In-Depth Information
In this level definition, a number of different blocks are defined. An iceberg (wall) tile is defined by the
# sign, a penguin by an r character, a background tile by a . character, and an empty tile by a space
character. Now you can write a method that uses this information to create the tiles and store them
somewhere (probably in a GameObjectGrid instance). This means you need different types of tiles: a
normal tile on which a penguin can stand, a transparent background tile, and a wall (iceberg) tile with
which a penguin can collide.
The Tile Class
To get things started, let's first write a basic Tile class. This class is a subclass of the
SpriteGameObject class. For now, you don't consider more complicated items in the level such as
penguins, seals, and sharks. You only look at background (transparent) tiles, normal tiles, and wall
(iceberg) tiles. Let's introduce a variable to represent these different varieties of tiles:
var TileType = {
normal: 0,
background: 1,
wall: 2
};
The Tile class is a basic extension of SpriteGameObject . In the constructor, you declare a member
variable type to store the type of tile that an instance represents:
function Tile(sprite, layer) {
SpriteGameObject.call(this, sprite, layer);
this.type = TileType.normal;
}
To accommodate transparent tiles, you override the draw method to draw the sprite only if the tile
isn't a background tile:
Tile.prototype.draw = function () {
if (this.type === TileType.background)
return;
SpriteGameObject.prototype.draw.call(this);
};
When you load the level, you create a tile for each character and store it in a grid structure such as
GameObjectGrid .
Other Level Information
In addition to the tiles, you need to store a few other things in the levelData variable:
Whether the level is locked
Whether the level has been solved by the player
A hint for the level
 
Search WWH ::




Custom Search