<li><label for="info_fps" >fps</label> <input id="info_fps" name="fps" value="" type="text"></li>
<li><label for="info_frame" >frame</label> <input id="info_frame" name="frame" value="" type="text"></li>
<li><div class="sep"></div></li>
- <li><label for="info_objects">objects</label> <input id="info_objects" name="objects" value="" type="text"></li>
+ <li><label for="info_active" >active</label> <input id="info_active" name="active" value="" type="text"></li>
<li><label for="info_units" >units</label> <input id="info_units" name="units" value="" type="text"></li>
<li><label for="info_bullets">bullets</label> <input id="info_bullets" name="bullets" value="" type="text"></li>
</ul>
tanks.Game = new Y.Class('Game', {
init : function init(viewport){
- Y.bindAll(this); // Seal all methods
+ Y.bindAll(this);
this.byId = {};
this.active = new Y.YArray();
this.loop = new EventLoop(this, FRAME_RATE);
- // this.resize = this.resize.bind(this);
- // this.tick = this.tick.bind(this);
-
this.root =
this.grid =
new Grid(COLUMNS,ROWS, CELL_SIZE)
if (unit instanceof Y.event.YEvent)
unit = unit.instance;
- console.log('killUnit(', unit, ')');
+ // console.log('killUnit(', unit, ')');
delete this.byId[unit.id];
this.active.remove(unit);
btank = new Tank(1);
btank.act = function(){ return this; };
+ btank.stats.shots = Infinity;
LBT.addUnit(btank, 0,0);
LBT.pathmap.removeBlocker(btank);
btank.shape.hide();
} while ( atX === x && atY === y);
btank.setLocation(x,y);
- return btank.fireProjectile(atX,atY);
+ return btank.shoot(atX,atY);
}
function updateBullets(n){
// Update performance info periodically
function updateInfo(){
- var loop = LBT.loop
- , fps = loop.fps()
- , n_units = LBT.units.size()
- , n_projs = LBT.bullets.size()
+ var loop = LBT.loop
+ , fps = loop.fps()
+ , n_active = LBT.active.size()
+ , n_units = LBT.units.size()
+ , n_projs = LBT.bullets.size()
;
$('#info [name=fps]').val( fps.toFixed(2) + " / " + loop.framerate );
$('#info [name=frame]').val( loop.frametime().toFixed(3)+" ms" );
$('#info #state').text( loop.running ? 'Running!' : ('Paused (tick '+TICKS+')') );
- $('#info [name=objects]').val( n_units+n_projs );
+ $('#info [name=active]').val( n_active );
$('#info [name=units]').val( n_units );
$('#info [name=bullets]').val( n_projs );
this.addEventListener('collide', self.onCollide.bind(this));
},
+
+
blocking : true,
bounces : 0,
bounceLimit : 1,
shots : 5 // max projectiles in the air at once
},
+ nShots : 0,
+
init : function init(align){
Thing.init.call(this, align);
- this.bullets = new Y.YArray();
+ this.onBulletDeath = this.onBulletDeath.bind(this);
},
- filterTarget : function filterTarget(unit){ return unit.align !== this.align; },
-
attack : function attack(unit){
var atk_cool = this.cooldowns.attr('attack');
if ( atk_cool.activate(NOW) )
return this;
},
- doAttack : function doAttack(target){
- this.fireProjectile(target);
+ doAttack : function doAttack(x,y){
+ this.shoot(x,y);
+ return this;
},
- fireProjectile : function fireProjectile(x,y){
+ shoot : function shoot(x,y){
+ if (this.nShots >= this.stats.shots)
+ return null;
+
var ProjectileType = this.projectile
, p = new ProjectileType(this, x,y);
- this.bullets.push(p);
+
+ this.nShots++;
+ p.addEventListener('destroy', this.onBulletDeath);
+
this.game.addUnit(p).render(this.game.level);
return p;
},
+ onBulletDeath : function onBulletDeath(evt){
+ this.nShots--;
+ },
+
getTurretLoc : function getTurretLoc(){
var loc = this.loc
, barrel = this.barrel, bb = barrel.boundingBox
var action = this.queue.shift();
if (action && action.type === 'fire') {
- // console.log('fire', [action.x, action.y], 'loc', this.tank.loc)
- this.tank.fireProjectile(action.x, action.y);
+ this.tank.shoot(action.x, action.y);
} else if ( this.activeKeys.size() )
this.move();