November 2011
Intermediate to advanced
348 pages
7h 2m
English
In this recipe, we'll create a Level class which will be used to render the level and provide an API to the bundary map.
Follow these steps to create a Level class:
Level constructor:/*
* Level class should have no knowledge
* of the Actor or HealthBar classes to
* keep it decoupled
*/
function Level(config){
this.controller = config.controller;
this.x = config.x;
this.y = config.y;
this.leftBounds = config.leftBounds;
this.rightBounds = config.rightBounds;
this.boundsData = null;
this.GRAVITY = 3; // px / second^2
this.MID_RGB_COMPONENT_VALUE = 128;
this.LEVEL_WIDTH = 6944;
this.setBoundsData();
}setBoundsData() method which extracts the zone data from the boundary map image:Level.prototype.setBoundsData ...
Read now
Unlock full access