Refactors shared Tank/Tower code into Unit.
authordsc <david.schoonover@gmail.com>
Mon, 11 Apr 2011 08:21:44 +0000 (01:21 -0700)
committerdsc <david.schoonover@gmail.com>
Mon, 11 Apr 2011 08:21:44 +0000 (01:21 -0700)
src/tanks/thing/tank.cjs
src/tanks/thing/tower.cjs
src/tanks/thing/unit.cjs

index da1fc80..629b261 100644 (file)
@@ -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);
     
     
     
index a62a373..4b665dd 100644 (file)
@@ -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);
     
     
     
index d081c34..59ec2df 100644 (file)
@@ -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