HTML and CSS Reference
In-Depth Information
Add the three methods in Listing 18-6 to the Q.TileLayer class in quintus_platformer.js . You
can put it before the prerenderBlock method, making sure you have your method-ending commas lined up
correctly.
Listing 18-6: Collision points checking in TileLayer
checkBounds: function(pos,col,start) {
start = start || 0;
for(var i=0;i<4;i++) {
var dir = this.directions[(i+start)%4];
var result = this.checkPoints(pos,col[dir],dir);
if(result) {
result.start = i+1;
return result;
}
}
return false;
},
checkPoints: function(pos,pts,which) {
for(var i=0,len=pts.length;i<len;i++) {
var result = this.checkPoint(pos.x+pts[i][0],
pos.y+pts[i][1],which);
if(result) {
result.point = pts[i];
return result;
}
}
return false;
},
checkPoint: function(x,y,which) {
var p = this.p,
tileX = Math.floor((x - p.x) / p.tileW),
tileY = Math.floor((y - p.y) / p.tileH);
if(p.tiles[tileY] && p.tiles[tileY][tileX] > 0) {
this.colBounds.tile = p.tiles[tileY][tileX];
this.colBounds.direction = which;
switch(which) {
case 'top':
this.colBounds.destX = x;
this.colBounds.destY = (tileY+1)*p.tileH + p.y + Q.dx;
break;
case 'bottom':
this.colBounds.destX = x;
this.colBounds.destY = tileY*p.tileH + p.y - Q.dx;
break;
 
 
Search WWH ::




Custom Search