Adds cooldown widget.
authordsc <david.schoonover@gmail.com>
Mon, 13 Dec 2010 17:51:55 +0000 (09:51 -0800)
committerdsc <david.schoonover@gmail.com>
Mon, 13 Dec 2010 17:51:55 +0000 (09:51 -0800)
src/ezl/index.cjs
src/ezl/loop/cooldown.cjs
src/ezl/widget/cooldown.cjs [new file with mode: 0644]
src/ezl/widget/index.cjs [new file with mode: 0644]
src/tanks/config.cjs
src/tanks/thing/tank.cjs
src/tanks/thing/thing.cjs
www/deps.html

index 2e52494..0b952af 100644 (file)
@@ -6,11 +6,12 @@
 var Y = require('Y').Y;
 
 Y.extend(exports, {
-    'Layer' : require('ezl/layer').Layer,
+    'Layer'  : require('ezl/layer').Layer,
     
-    'loc'   : require('ezl/loc'),
-    'loop'  : require('ezl/loop'),
-    'math'  : require('ezl/math'),
-    'shape' : require('ezl/shape'),
-    'util'  : require('ezl/util')
+    'loc'    : require('ezl/loc'),
+    'loop'   : require('ezl/loop'),
+    'math'   : require('ezl/math'),
+    'shape'  : require('ezl/shape'),
+    'util'   : require('ezl/util'),
+    'widget' : require('ezl/widget')
 });
index 3c30c07..fbf4d45 100644 (file)
@@ -38,4 +38,4 @@ Y.subclass('Cooldown', {
         return Math.min(1.0, this.elapsed / this.cooldown);
     }
     
-});
+});
\ No newline at end of file
diff --git a/src/ezl/widget/cooldown.cjs b/src/ezl/widget/cooldown.cjs
new file mode 100644 (file)
index 0000000..dba3caa
--- /dev/null
@@ -0,0 +1,63 @@
+var Y = require('Y').Y
+,   Layer = require('ezl/layer').Layer
+
+,   PI             = Math.PI
+,   QUARTER_PI     = PI/4
+,   HALF_PI        = PI/2
+,   PI_AND_HALF    = PI + HALF_PI
+,   TWO_PI         = PI*2
+,
+
+
+
+CooldownGauge =
+exports['CooldownGauge'] =
+Layer.subclass('CooldownGauge', function setupCooldownGauge(CooldownGauge){
+    Y.extend(this, {
+        _cssClasses : 'ezl layer cooldown',
+        fillStyle   : '#000000',
+        strokeStyle : 'transparent',
+        lineWidth   : 0,
+        globalAlpha : 0.25
+    });
+    
+    
+    this['init'] =
+    function initCooldownGauge(cooldown, w,h){
+        Layer.init.call(this);
+        this.cooldown = cooldown;
+        this.size(w,h);
+        this.layer.css('overflow', 'hidden');
+    };
+    
+    this['draw'] =
+    function draw(ctx, force) {
+        this.dirty = true; // Always redraw as the cooldown has updated
+        return Layer.fn.draw.apply(this, arguments);
+    };
+    
+    this['drawShape'] =
+    function drawShape(ctx){
+        var cool = this.cooldown;
+        
+        if (cool.ready)
+            return this;
+        
+        var p = cool.ratio()
+        ,   w = this.layerWidth, h = this.layerHeight
+        ,   x = w*0.5, y = h*0.5
+        ,   amt = HALF_PI + (1 - p)*PI_AND_HALF;
+        
+        ctx.arc(x,y, w, HALF_PI, amt, false);
+        ctx.lineTo(x,y);
+        ctx.lineTo(x,0);
+        ctx.fill();
+        ctx.stroke();
+        
+        return this;
+    };
+    
+    
+});
+
+
diff --git a/src/ezl/widget/index.cjs b/src/ezl/widget/index.cjs
new file mode 100644 (file)
index 0000000..c0e2942
--- /dev/null
@@ -0,0 +1,5 @@
+var Y = require('Y').Y;
+
+Y.extend(exports, {
+    'CooldownGauge' : require('ezl/widget/cooldown').CooldownGauge
+});
index c7f2989..aa180cf 100644 (file)
@@ -4,19 +4,20 @@ var Y = require('Y').Y
 ,   defaults =
 exports['defaults'] = {
     game : {
-        timeDilation     : 1.0,
-        gameoverDelay    : 1000
+        timeDilation       : 1.0,
+        gameoverDelay      : 1000
     },
     ui : {
-        createGridCanvas : 1,
-        createGridTable  : 0,
-        showGridCoords   : 0,
-        showCountdown    : 1
+        createGridCanvas   : 1,
+        createGridTable    : 0,
+        showGridCoords     : 0,
+        showAttackCooldown : 0,
+        showCountdown      : (document.location.host.toString() !== 'tanks.woo')
     },
     pathing : { 
-        overlayAIPaths    : 0,
-        overlayPathmap    : 0,
-        traceTrajectories : 0
+        overlayAIPaths     : 0,
+        overlayPathmap     : 0,
+        traceTrajectories  : 0
     }
 };
 
index 2613072..2ab69e1 100644 (file)
@@ -1,12 +1,13 @@
-var Y          = require('Y').Y
-,   Thing      = require('tanks/thing/thing').Thing
-,   Bullet     = require('tanks/thing/bullet').Bullet
-,   Trajectory = require('tanks/map/trajectory').Trajectory
-,   Vec        = require('ezl/math/vec').Vec
-,   Cooldown   = require('ezl/loop').Cooldown
-,   shape      = require('ezl/shape')
-,   Rect       = shape.Rect
-,   Circle     = shape.Circle
+var Y             = require('Y').Y
+,   Thing         = require('tanks/thing/thing').Thing
+,   Bullet        = require('tanks/thing/bullet').Bullet
+,   Trajectory    = require('tanks/map/trajectory').Trajectory
+,   Vec           = require('ezl/math/vec').Vec
+,   Cooldown      = require('ezl/loop').Cooldown
+,   CooldownGauge = require('ezl/widget').CooldownGauge
+,   shape         = require('ezl/shape')
+,   Rect          = shape.Rect
+,   Circle        = shape.Circle
 
 ,   isBullet = Y.is(Bullet)
 ,   BULLET_MOVE_PER_FRAME = MS_PER_FRAME * Bullet.prototype.stats.move*REF_SIZE/1000
@@ -58,6 +59,7 @@ Thing.subclass('Tank', function(Tank){
     this['init'] =
     function initTank(align){
         Thing.init.call(this, align);
+        this.coolgauge = new CooldownGauge(this.cooldowns.attack, this.width+1,this.height+1);
         this.onBulletDeath = this.onBulletDeath.bind(this);
         this.addEventListener('destroy', destroyPath);
     };
@@ -404,6 +406,9 @@ Thing.subclass('Tank', function(Tank){
                 .fill(this.bodyColor)
                 .appendTo( parent ) ;
         
+        if (this.showAttackCooldown)
+            this.shape.append(this.coolgauge);
+        
         this.turret =
             new Circle(r)
                 .position(w2, h2)
index 56b5f95..24cf897 100644 (file)
@@ -6,20 +6,21 @@ var Y           = require('Y').Y
 ,   Loc         = require('ezl/loc/loc').Loc
 ,   BoundingBox = require('ezl/loc/boundingbox').BoundingBox
 ,   Cooldown    = require('ezl/loop').Cooldown
+
+,   config      = require('tanks/config').values
 ,
 
 
 Thing =
 exports['Thing'] =
 new evt.Class('Thing', {
+    showAttackCooldown : config.ui.showAttackCooldown,
     
     // Attributes
     stats: {
         hp        : 1,          // health
-        
         move      : 1.0,        // 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
index b552bb9..49e9edf 100644 (file)
 <script src="build/ezl/loc.js" type="text/javascript"></script>
 <script src="build/ezl/layer.js" type="text/javascript"></script>
 <script src="build/ezl/shape/shape.js" type="text/javascript"></script>
+<script src="build/ezl/widget/cooldown.js" type="text/javascript"></script>
 <script src="build/ezl/shape/line.js" type="text/javascript"></script>
 <script src="build/ezl/shape/polygon.js" type="text/javascript"></script>
+<script src="build/ezl/widget.js" type="text/javascript"></script>
 <script src="build/ezl/shape/circle.js" type="text/javascript"></script>
 <script src="build/ezl/shape/rect.js" type="text/javascript"></script>
 <script src="build/ezl/shape.js" type="text/javascript"></script>