From b7ab7115e43928091b5a29a396c713b7930a58e3 Mon Sep 17 00:00:00 2001 From: dsc Date: Mon, 13 Dec 2010 09:51:55 -0800 Subject: [PATCH] Adds cooldown widget. --- src/ezl/index.cjs | 13 +++++---- src/ezl/loop/cooldown.cjs | 2 +- src/ezl/widget/cooldown.cjs | 63 +++++++++++++++++++++++++++++++++++++++++++ src/ezl/widget/index.cjs | 5 +++ src/tanks/config.cjs | 19 +++++++------ src/tanks/thing/tank.cjs | 23 +++++++++------ src/tanks/thing/thing.cjs | 5 ++- www/deps.html | 2 + 8 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 src/ezl/widget/cooldown.cjs create mode 100644 src/ezl/widget/index.cjs diff --git a/src/ezl/index.cjs b/src/ezl/index.cjs index 2e52494..0b952af 100644 --- a/src/ezl/index.cjs +++ b/src/ezl/index.cjs @@ -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') }); diff --git a/src/ezl/loop/cooldown.cjs b/src/ezl/loop/cooldown.cjs index 3c30c07..fbf4d45 100644 --- a/src/ezl/loop/cooldown.cjs +++ b/src/ezl/loop/cooldown.cjs @@ -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 index 0000000..dba3caa --- /dev/null +++ b/src/ezl/widget/cooldown.cjs @@ -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 index 0000000..c0e2942 --- /dev/null +++ b/src/ezl/widget/index.cjs @@ -0,0 +1,5 @@ +var Y = require('Y').Y; + +Y.extend(exports, { + 'CooldownGauge' : require('ezl/widget/cooldown').CooldownGauge +}); diff --git a/src/tanks/config.cjs b/src/tanks/config.cjs index c7f2989..aa180cf 100644 --- a/src/tanks/config.cjs +++ b/src/tanks/config.cjs @@ -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 } }; diff --git a/src/tanks/thing/tank.cjs b/src/tanks/thing/tank.cjs index 2613072..2ab69e1 100644 --- a/src/tanks/thing/tank.cjs +++ b/src/tanks/thing/tank.cjs @@ -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) diff --git a/src/tanks/thing/thing.cjs b/src/tanks/thing/thing.cjs index 56b5f95..24cf897 100644 --- a/src/tanks/thing/thing.cjs +++ b/src/tanks/thing/thing.cjs @@ -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 diff --git a/www/deps.html b/www/deps.html index b552bb9..49e9edf 100644 --- a/www/deps.html +++ b/www/deps.html @@ -35,8 +35,10 @@ + + -- 1.7.0.4