E =
game.addThing(new Tank(2), 0,5);
- // game.addThing(new Tank(2), 1,0);
- // game.addThing(new Tank(2), 8,1);
+ game.addThing(new Tank(2), 1,0);
+ game.addThing(new Tank(2), 8,1);
I = game.addThing(new Item(), 8,8);
},
, SQRT_TWO = Math.sqrt(2)
+
, PASSABLE = 1 // Does not obstruct other objects
-, BLOCKING = 2 // Objstructs other blockers
+, BLOCKING = 2 // Obstructs other blockers
, ZONE = 3 // Does not obstruct other objects, but still collides with them
,
for (ix=-1; ix<2; ix++) {
for (iy=-1; iy<2; iy++) {
- // if (ix === 0 && iy === 0)
- if ( (ix === 0 && iy === 0) || (abs(ix) === 1 && abs(iy) === 1) ) // skipping diagonals
+ // Skip self
+ if (ix === 0 && iy === 0)
continue;
+
+ cost = 1;
x1 = x + ix*SIZE; y1 = y + iy*SIZE;
x2 = x1+SIZE; y2 = y1+SIZE;
+
+ // filter squares outside bounds
if ( pm.x1 >= x1 || pm.y1 >= y1 ||
pm.x2 <= x2 || pm.y2 <= y2 )
continue;
- // TODO: handle diagonals: need to ensure we don't try to move through a corner
- // cost = ( abs(ix) === 1 && abs(iy) === 1 ) ? SQRT_TWO : 1;
- cost = 1;
+
+ // Diagonal square
+ if ( abs(ix) === 1 && abs(iy) === 1 ) {
+ cost = SQRT_TWO;
+
+ // Ensure we don't cut a blocked corner
+ if ( pm._getSquare(x1,y).blocked || pm._getSquare(x,y1).blocked )
+ continue;
+ }
+
sq = pm._getSquare(x1,y1);
- // if ( !sq.blocked ) neighbors.push([ sq, cost*SIZE ]);
neighbors.push([ sq, cost*SIZE ]);
}
}
this['act'] =
function act(elapsed, now){
+ var ai = this.ai;
this.elapsed = elapsed;
this.now = now;
- var ai = this.ai;
-
- this.continueMove();
- return;
+ // this.continueMove();
+ // return;
// Check to see if we should obey our last decision, and not recalc
if (this.forceCurrentMove && this.forceCurrentMove() && this.currentMoveLimit > now) {
this['continueMove'] =
function continueMove(){
- if ( !this.currentMove ){ //|| this.ai.path.ready ){
+ if ( !this.currentMove || this.ai.path.ready ){
var target = this.findNearEnemies(10000).shift();
if (target)
this.calculatePath(target.loc);