topical media & game development
mobile-game-ch21-scribble-public-js-quintus-platformer-original.js / js
Quintus.Platformer = function(Q) {
Q.TileLayer = Q.Sprite.extend({
init: function(props) {
this._super(_(props).defaults({
tileW: 32,
tileH: 32,
blockW: 10,
blockH: 10,
type: 1
}));
if(this.p.dataAsset) {
this.load(this.p.dataAsset);
}
this.blocks = [];
// reusable collision object
this.colBounds = {};
this.directions = [ 'top','left','right','bottom'];
},
load: function(dataAsset) {
var data = _.isString(dataAsset) ? Q.asset(dataAsset) : dataAsset;
this.p.tiles = data;
this.p.rows = data.length;
this.p.cols = data[0].length;
this.p.w = this.p.rows * this.p.tileH;
this.p.h = this.p.cols * this.p.tileW;
},
draw: function(ctx) {
var p = this.p,
tiles = p.tiles,
sheet = this.sheet();
for(var y=0;y < p.rows;y++) {
if(tiles[y]) {
for(var x =0;x < p.cols;x++) {
if(tiles[y][x]) {
sheet.draw(ctx,
x*p.tileW + p.x,
y*p.tileH + p.y,
tiles[y][x]);
}
}
}
}
}
});
};
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.