init : function initPlayer(align){
Tank.init.call(this, align);
- this.gameLog = [];
this.queue = [];
this.activeKeys = new Y.YArray();
this.inventory = new Inventory(this);
this.applyRecoilMove();
- var action;
- if (this.replayMode) {
- action = this.nextMove;
-
- if (!action || TICKS < action.ticks)
- return this;
-
- // var drift = TICKS - action.ticks;
- // if (drift) console.warn('replay drift: '+(drift > 0 ? '+' : '')+drift);
- this.nextMove = this.replay.shift();
-
- } else {
- action = this.queue.shift();
-
- if ( !action && this.activeKeys.size() ) {
- var to = this.getPlayerMove();
- if (to) action = { 'type':'move', 'data':to };
- }
+ var action = this.queue.shift();
+ if ( !action && this.activeKeys.size() ) {
+ var to = this.getPlayerMove();
+ if (to) action = { 'type':'move', 'data':to };
}
if ( !action ) {
var data = action.data;
switch (action.type) {
- case 'shoot':
- if (!this.replayMode && this.enableGameLogging)
- this.gameLog.push({ 'type':'shoot', 'ticks':TICKS, 'data':data.toObject() });
- this.shoot(data.x, data.y);
- break;
-
- case 'move':
- this.move(data.x, data.y);
- break;
+ case 'shoot': this.shoot(data.x, data.y); break;
+ case 'move': this.move(data.x, data.y); break;
default:
console.error('wtf unknown player action "'+action.type+'"', action);
if (!dir) return;
// @see Tank.move()
- var to = this.loc.moveByDir(dir, this.stats.move.val * SQUARETH);
- if (!this.replayMode && this.enableGameLogging)
- this.gameLog.push({ 'type':'move', 'ticks':TICKS, 'data':to.toObject() });
-
- return to;
+ return this.loc.moveByDir(dir, this.stats.move.val * SQUARETH);
},
},
keydown : function keydown(evt){
- if ( !this.game.loop.running || this.replayMode ) return;
+ if ( !this.game.loop.running ) return;
this.updateMeta(evt);
},
mousedown : function mousedown(evt){
- if ( !this.game.loop.running || this.replayMode ) return;
+ if ( !this.game.loop.running ) return;
switch (evt.which) {
case 1: evt.leftMouse = true;
},
mousemove : function mousemove(evt){
- if ( !this.game.loop.running || this.replayMode ) return;
+ if ( !this.game.loop.running ) return;
this.rotateBarrelRelPage(evt.pageX, evt.pageY);
}
},
/**
- * Fires this agent's cannon. If a target location is omitted, the shot
- * will be fired in the direction of the tank's current barrel rotation.
+ * Fires this agent's cannon at a target location.
*
- * @param {Number} [x] Target X coordinate.
- * @param {Number} [y] Target Y coordinate.
+ * @param {Number} x Target X coordinate.
+ * @param {Number} y Target Y coordinate.
*/
shoot : function shoot(x,y){
if ( !this.ableToShoot() )
return null;
if (x instanceof Array) { y = x[_Y]; x = x[_X]; }
- var xydef = (x !== undefined && y !== undefined);
- if (xydef && this.hasBarrel)
+
+ if (x === undefined || y === undefined) {
+ console.error('Unit.fire() without args!', this);
+ return null;
+ }
+
+ if ( this.hasBarrel )
this.rotateBarrel(x,y);
// Additional space on each side which must be clear around the
if ( blockers.size() )
return null; // console.log('squelch!', blockers);
- if (!xydef && this.hasBarrel) {
- var theta = this.getBarrelAngle()
- , sin = Math.sin(theta), cos = Math.cos(theta);
- x = tx + REF_SIZE*cos;
- y = ty + REF_SIZE*sin;
- }
-
this.cooldowns.attack.activate(this.now);
this.nShots++;
// Recoil
// TODO: allow stacking recoil
- var recoil_dist = this.stats.recoil.val * RECOIL_DIST_UNIT
- , recoil_speed = recoil_dist / RECOIL_DURATION
- ;
- this.recoil.vec = new Vec(tx-x, ty-y);
- this.recoil.remaining = RECOIL_DURATION;
- this.recoil.speed = recoil_speed;
- this.applyRecoilMove();
+ var recoil_val = this.stats.recoil.val;
+ if (recoil_val) {
+ var recoil_dist = recoil_val * RECOIL_DIST_UNIT
+ , recoil_speed = recoil_dist / RECOIL_DURATION
+ ;
+ this.recoil.vec = new Vec(tx-x, ty-y);
+ this.recoil.remaining = RECOIL_DURATION;
+ this.recoil.speed = recoil_speed;
+ this.applyRecoilMove();
+ }
var p = new Projectile(this, tx,ty, x,y);
p.on('destroy', this.onBulletDeath);