LBT = new tanks.Game();
ctx = LBT.level.ctx;
- P = LBT.addUnit(new PlayerTank(1), 8,9);
- E = LBT.addUnit(new Tank(2), 1,2);
+ P = LBT.addUnit(new PlayerTank(1), 6,9);
+ E =
+ LBT.addUnit(new Tank(2), 0,1);
+ LBT.addUnit(new Tank(2), 1,0);
+ LBT.addUnit(new Tank(2), 8,1);
setupUI();
return d1 + d2;
},
- path : function path(start, end){
+ path : function path(start, end, id){
var size = this.gridSquareSize, floor = Math.floor
, grid = this.grid()
;
if (tanks.config.pathing.overlayAIPaths)
- this.drawPath(startN, path);
+ this.drawPath(id, startN, path);
return path
.invoke('scale', size)
.end();
},
- drawPath : function drawPath(start, path){
- var size = this.gridSquareSize, off = size*0.15
+ drawPath : function drawPath(id, start, path){
+ var size = this.gridSquareSize, off
, w = this.width-2, h = this.height-2
, el = this.game.viewport
, grid = this.grid()
- , canvas = $('.path', el)[0]
+ , canvas = $('#path'+id, el)[0]
;
if (!canvas) {
- canvas = $('<canvas class="path" style="position:absolute"/>').appendTo(el)[0];
+ canvas = $('<canvas id="path'+id+'" class="path" style="position:absolute"/>').appendTo(el)[0];
$(canvas).width(w).height(h);
canvas.width = w;
canvas.height = h;
// Draw path
- var r = size/2 - off;
+ off = size*0.3;
- function drawStep(p, i){
- var x = p.x*size + off + r
+ function drawStep(p){
+ var r = size/2 - off
+ , x = p.x*size + off + r
, y = p.y*size + off + r ;
ctx.beginPath();
}
this.drawStep = drawStep;
- ctx.fillStyle = 'rgba(0,0,0,0.2)';
+ ctx.fillStyle = 'rgba(0,0,0,0.1)';
+ drawStep( start );
path.forEach(drawStep);
// Draw start
- ctx.fillStyle = 'rgba(0,255,0,0.2)';
- drawStep(start, 0);
+ off = size*0.15;
+
+ ctx.fillStyle = 'rgba(0,255,0,0.05)';
+ drawStep( start );
// Draw finish
- ctx.fillStyle = 'rgba(0,0,255,0.2)';
+ ctx.fillStyle = 'rgba(0,0,255,0.05)';
drawStep( path.last() );
$(canvas).show();
},
- clearPath : function clearPath(){
+ destroyPath : function destroyPath(id){
+ $('#path'+id, this.game.viewport).remove();
+ },
+
+ hidePath : function hidePath(id){
+ $('#path'+id, this.game.viewport).hide();
+ },
+
+ hidePaths : function hidePaths(){
$('.path', this.game.viewport).hide();
},
var self = this;
this.addEventListener('destroy', function(){
- this.game.pathmap.clearPath();
+ this.game.pathmap.destroyPath(this.id);
});
},
if (!t) return;
- pm.clearPath();
-
// console.log(this, 'moving toward', t);
var end = t.boundingBox.midpoint()
, bb = this.boundingBox
, mid = bb.midpoint()
, start = mid
- , path = this.lastPath = pm.path(start, end)
+ , path = this.lastPath = pm.path(start, end, this.id)
, to = this.currentMove = path[0]
;