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')
});
return Math.min(1.0, this.elapsed / this.cooldown);
}
-});
+});
\ No newline at end of file
--- /dev/null
+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;
+ };
+
+
+});
+
+
--- /dev/null
+var Y = require('Y').Y;
+
+Y.extend(exports, {
+ 'CooldownGauge' : require('ezl/widget/cooldown').CooldownGauge
+});
, 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
}
};
-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
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);
};
.fill(this.bodyColor)
.appendTo( parent ) ;
+ if (this.showAttackCooldown)
+ this.shape.append(this.coolgauge);
+
this.turret =
new Circle(r)
.position(w2, h2)
, 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
<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>