HTML and CSS Reference
In-Depth Information
5. In the exising runway view object, we add the logic related to the integer map and
the Game loop. This view object has reference to all the created iles:
game.view.runway = {
...
/* existing runway code here */
runwayIndex: 0,
tick: function(round) {
// move existing tiles
for(var i=0, len=this.tiles.length; i<len; i++) {
var tile = this.tiles[i];
tile.moveDown();
}
// increase the runway Index
this.runwayIndex += 1;
if (this.runwayIndex >= game.data.runway.length) {
this.runwayIndex = 0;
}
// create new tiles
var row = game.data.runway[this.runwayIndex];
for(var i=0, len=row.length; i<len;i++){
this.createTile(row[i], i * game.TILE_HEIGHT, 0);
}
}
};
6. Inside the Tile deiniion, we deine a new method, movedown , to change the
ile posiion:
Tile.prototype.moveDown = function() {
this.y += game.TILE_HEIGHT;
if (this.element && this.y > game.BOUNDARY) {
game.view.floor.removeChild(this.element);
this.element = undefined;
}
}
7. We don't want to move a ile forever ater it is out of the viewable screen area.
Therefore, we will set a boundary in the setting.js file:
game.BOUNDARY = 1000;
 
Search WWH ::




Custom Search