From 7c286886a7a0be828297ccf631244f11d0610fed Mon Sep 17 00:00:00 2001 From: dsc Date: Mon, 11 Apr 2011 01:21:44 -0700 Subject: [PATCH] Refactors shared Tank/Tower code into Unit. --- src/tanks/thing/tank.cjs | 8 +------- src/tanks/thing/tower.cjs | 10 ++-------- src/tanks/thing/unit.cjs | 24 +++++++++++++++++++++--- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/tanks/thing/tank.cjs b/src/tanks/thing/tank.cjs index da1fc80..629b261 100644 --- a/src/tanks/thing/tank.cjs +++ b/src/tanks/thing/tank.cjs @@ -84,16 +84,10 @@ Unit.subclass('Tank', function(Tank){ this['init'] = function initTank(align){ Unit.init.call(this, align); - this.projectile = this.defaultProjectile = Bullet.lookup(this.projectile); - this.colors = Y.extend({}, this.colors); this.atkGauge = new CooldownGauge(this.cooldowns.attack, this.width+1,this.height+1); - this.onBulletDeath = this.onBulletDeath.bind(this); }; - Lootable.mixInto(Tank); - - this['onBulletDeath'] = - function onBulletDeath(evt){ this.nShots--; }; + // Lootable.mixInto(Tank); diff --git a/src/tanks/thing/tower.cjs b/src/tanks/thing/tower.cjs index a62a373..4b665dd 100644 --- a/src/tanks/thing/tower.cjs +++ b/src/tanks/thing/tower.cjs @@ -70,16 +70,10 @@ Unit.subclass('Tower', function(Tower){ this['init'] = function initTower(align){ Unit.init.call(this, align); - this.projectile = this.defaultProjectile = Bullet.lookup(this.projectile); - this.colors = Y.extend({}, this.colors); - this.atkGauge = new CooldownGauge(this.cooldowns.attack, this.width+1,this.height+1); - this.onBulletDeath = this.onBulletDeath.bind(this); + // this.atkGauge = new CooldownGauge(this.cooldowns.attack, this.width+1,this.height+1); }; - Lootable.mixInto(Tower); - - this['onBulletDeath'] = - function onBulletDeath(evt){ this.nShots--; }; + // Lootable.mixInto(Tower); diff --git a/src/tanks/thing/unit.cjs b/src/tanks/thing/unit.cjs index d081c34..59ec2df 100644 --- a/src/tanks/thing/unit.cjs +++ b/src/tanks/thing/unit.cjs @@ -1,10 +1,12 @@ var Y = require('Y').Y , Vec = require('ezl/math/vec').Vec -, constants = require('tanks/constants') -, BoundsType = constants.BoundsType -, DensityType = constants.DensityType +, constants = require('tanks/constants') +, BoundsType = constants.BoundsType +, DensityType = constants.DensityType , Thing = require('tanks/thing/thing').Thing +, Bullet = require('tanks/thing/bullet').Bullet +, Lootable = require('tanks/mixins/lootable').Lootable , LinearTrajectory = require('tanks/map/pathing/lineartrajectory').LinearTrajectory , Traversal = require('tanks/map/pathing/traversal').Traversal @@ -16,23 +18,39 @@ var Y = require('Y').Y Unit = exports['Unit'] = Thing.subclass('Unit', { + __mixins__ : [ Lootable ], + __bind__ : [ 'onBulletDeath' ], + isUnit : true, isCombatant : true, hasBarrel : false, + projectile : 'bullet', + defaultProjectile : null, + + colors : {}, recoil : { remaining : 0, speed : 0, vec : null }, + + align : null, + buffs : null, + nShots : 0, init : function initUnit(align){ Thing.init.call(this, align); this.recoil = Y.extend({}, this.recoil); + this.colors = Y.extend({}, this.colors); + this.projectile = this.defaultProjectile = Bullet.lookup(this.projectile); }, + onBulletDeath : function onBulletDeath(evt){ + this.nShots = Math.max(0, this.nShots-1); + }, /** * Fires this agent's cannon. If a target location is omitted, the shot -- 1.7.0.4