HTML and CSS Reference
In-Depth Information
List of Tiles
Different tiles can exhibit different behaviors and render differently in the game, and you need one class for each tile
type. A basic implementation has only a constructor and no custom methods for rendering or behavior. Each tile can
be found either by name or by ID. is an autogenerated, 0-based integer that will be used in map serialization.
Specific types of tiles are described in Chapter 6.
You will use the extendTile function to implement inheritance, as is the case in object-oriented programming.
This function will help you spawn different types of tiles, and each can have a specific rendering algorithm or logic
to determine which sprite you need to draw:
function extendTile(Type, obj) {
var newClass = function Tile(name, obj) { = name;
if (obj) for (var key in obj)
if (obj.hasOwnProperty(key))
this[key] = obj[key];
var proto = new Type();
for (var key in obj)
if (obj.hasOwnProperty(key))
proto[key] = obj[key];
newClass.prototype = proto;
return newClass;
Now, you use extendTile to generate basic tiles. This example is for a dual-layered structure made up of
SurfaceTile and ObjectTile ; object tiles are placed on top of the surface tiles:
var Tile = extendTile(function() {}, {})
var SurfaceTile = extendTile(Tile, {type: 0, layer: 0})
var ObjectTile = extendTile(Tile, {type: 1, layer: 1})
The TileList is going to be used for tile storage. You can add new tiles, get them by name or JD, and add new
properties to already created tiles, using the apply method:
var TileList = function() {
this.byId = []
this.byName = {}
TileList.prototype = {
defaultSurface : null, defaultObject: null,
add : function(tile) {
// if tile exists, dont add it
if (this.byName[]) return = this.byId.length;
return this.byName[] = tile;
Search WWH ::

Custom Search