// Attributes
stats: {
hp : 1, // health
-
- move : 0.75, // move speed (squares/sec)
+ move : 0.75, // move speed (squares/sec)
rotate : HALF_PI, // rotation speed (radians/sec)
-
power : 1, // attack power
speed : 0.5, // attack cool (sec)
shots : 5 // max projectiles in the air at once
if (!dir) return;
// @see Tank.move()
- this.move(this.loc.moveByDir(dir, REF_SIZE));
+ this.move(this.loc.moveByDir(dir, this.stats.move * SQUARETH));
},
- _move : function move(){
- var dir = this.activeKeys
- .unique()
- .sort()
- .join(' ');
-
- if (!dir) return;
-
- var toLoc = this.loc.moveByDir(dir, (this.stats.move * SQUARETH))
-
- , x = toLoc.x, y = toLoc.y
- , bb = this.boundingBox.relocated(x,y)
-
- , blockers = this.game.pathmap.get(bb.x1,bb.y1, bb.x2,bb.y2).remove(this)
- ;
-
- if ( !blockers.size() )
- this.game.moveUnitTo(this, x,y);
- },
+ // _move : function _move(){
+ // var dir = this.activeKeys
+ // .unique()
+ // .sort()
+ // .join(' ');
+ //
+ // if (!dir) return;
+ //
+ // var toLoc = this.loc.moveByDir(dir, (this.stats.move * SQUARETH))
+ //
+ // , x = toLoc.x, y = toLoc.y
+ // , bb = this.boundingBox.relocated(x,y)
+ //
+ // , blockers = this.game.pathmap.get(bb.x1,bb.y1, bb.x2,bb.y2).remove(this)
+ // ;
+ //
+ // if ( !blockers.size() )
+ // this.game.moveUnitTo(this, x,y);
+ // },
// AI "Cooldowns" (max frequency of each action per sec)
ai : {
- path : 1.5, // calculate a path to enemy
+ path : 1.0, // calculate a path to enemy
dodge : 1.0, // dodge an incoming bullet
shootIncoming : 0.5, // shoot down incoming bullet
shootEnemy : 0.75 // shoot at enemy tank if in range
*/
this['shoot'] =
function shoot(x,y){
- var WIGGLE = 4 // additional space which must be clear in front of the barrel
+ var WIGGLE = 3 // additional space which must be clear in front of the barrel
, xydef = (x !== undefined && y !== undefined)
;
if ( this.nShots >= this.stats.shots || !this.cooldowns.attack.activate(NOW) )
return null;
- var barrel = this.barrel
- , mid = this.midpoint
- , bb = this.boundingBox
- , w2 = bb.width/2, h2 = bb.height/2
- , x0 = bb.x1+w2, y0 = bb.y1+h2
-
- , theta = barrel.transform.rotate
- , sin = Math.sin(theta), cos = Math.cos(theta)
-
- , x1 = x0 + w2*cos, y1 = y0 + h2*sin
- , sz = (barrel.boundingBox.width - w2)/2 + WIGGLE
- , blockers = this.game.pathmap.get(x1-sz,y1-sz, x1+sz,y1+sz).remove(this)
+ var tloc = this.getTurretLoc()
+ , tx = tloc.x, ty = tloc.y
+ , x1 = tx - WIGGLE, y1 = ty - WIGGLE
+ , x2 = tx + WIGGLE, y2 = ty + WIGGLE
+ , blockers = this.game.pathmap.get(x1,y1, x1,y1).remove(this)
+
+ // var barrel = this.barrel
+ // , loc = this.loc
+ // , bb = this.boundingBox
+ // , w2 = bb.width/2, h2 = bb.height/2
+ // , x0 = bb.x1+w2, y0 = bb.y1+h2
+ //
+ // , theta = barrel.transform.rotate
+ // , sin = Math.sin(theta), cos = Math.cos(theta)
+ //
+ // , x1 = x0 + w2*cos, y1 = y0 + h2*sin
+ // , sz = (barrel.boundingBox.width - w2)/2 + WIGGLE
+ // , blockers = this.game.pathmap.get(x1-sz,y1-sz, x1+sz,y1+sz).remove(this)
;
if ( blockers.size() )
return null; // console.log('squelch!', blockers);
if (!xydef) {
- x = x0 + REF_SIZE*cos;
- y = y0 + REF_SIZE*sin;
+ var theta = this.barrel.transform.rotate
+ , sin = Math.sin(theta), cos = Math.cos(theta);
+ x = tx + REF_SIZE*cos;
+ y = ty + REF_SIZE*sin;
}
var ProjectileType = this.projectile
this['getTurretLoc'] =
function getTurretLoc(){
- var WIGGLE = 8
- , loc = this.loc, mid = this.midpoint
+ var WIGGLE = 9 // 1.4 * 6 for max diagonal
+ , loc = this.loc
, barrel = this.barrel
, theta = barrel.transform.rotate
, sin = Math.sin(theta), cos = Math.cos(theta)
, len = barrel.boundingBox.width + WIGGLE
- , x = mid.x + len*cos
- , y = mid.y + len*sin
+ , x = loc.x + len*cos
+ , y = loc.y + len*sin
;
// console.log('getTurretLoc()', 'loc:', loc, '(x,y):', [x,y]);
return new Vec(x,y);