HTML and CSS Reference
In-Depth Information
}
}
Pickup.prototype = new AnimationManager;
3.
The next step involves creating a new pickup array object within the Level object
and illing this array with the positions of a number of collectible items, that is,
pickups, inside of the Level constructor. Insert the following code at the top of the
Level script:
this.pickup = new Object();
this.tileWidth = 0;
this.tileHeight = 0;
this.InitLevel = function(width, height) {
this.tileWidth = tile.width;
this.tileHeight = tile.height;
for(var i = 0; i < 50; i++) {
this.tiles[i] = 1;
}
this.pickup['1'] = 'Berry';
this.AddTile(width, height);
this.AddPickup(width, height);
return this;
}
4.
We then need to implement a function that will draw each of the pickups to the
canvas at the position speciied within the pickup object array.
this.AddPickup = function(width, height) {
var x, y;
for(var i = 0; i < this.tiles.length; ++i){
if(this.pickup[i]){
x = i * this.tileWidth + this.tileWidth / 2;
y = height - this.TerrainHeight(i);
if(this.pickup[i] == 'Berry') {
 
Search WWH ::




Custom Search