, KNOWN_CLASSES = type.type.KNOWN_CLASSES
, classToString = function toString(){ return this.className+"()"; }
+, classStatics = [ 'instantiate', 'fabricate', 'subclass' ]
;
/**
eval(constructor);
// Copy Class statics
- for (var k in ClassFactory)
+ for (var i=0, L=classStatics.length; i<L; ++i) {
+ var k = classStatics[i];
NewClass[k] = ClassFactory[k];
+ }
// Copy parent methods, then add new instance methods
for (var k in parentMembers)
;
for ( var name in o )
acc[name] = fn.call(cxt, o[name], name, o);
- return acc;
+ return Y(acc);
},
'forEach' : function forEach( fn, context ){
for ( var name in o )
if ( fn.call( context || this, o[name], name, o ) )
acc[name] = o[name];
- return acc;
+ return Y(acc);
},
'indexOf' : function indexOf( value ){
return o;
if (arguments.length === 1)
names = core.map(o, op.nth(1));
- else
+ else if ( !(names instanceof Array) )
names = slice.call(arguments, 1);
core.forEach(names, bindName, o);
return o;
, classToString = function toString(){ return this.className+"()"; }
, classMagic = [ '__static__', '__mixins__', '__emitter__', '__bases__', '__initialise__' ]
, mixinSkip = [ '__mixin_skip__', 'onMixin', 'onInit', 'init' ].concat(classMagic)
+, classStatics = [ 'instantiate', 'fabricate', 'subclass' ]
,
eval(constructor);
// Copy Class statics
- for (var k in ClassFactory) {
- var v = ClassFactory[k];
- if ( isFunction(v) && !(k in Y.event.Emitter.methods) )
- NewClass[k] = v;
+ for (var i=0, L=classStatics.length; i<L; ++i) {
+ var k = classStatics[i];
+ NewClass[k] = ClassFactory[k];
}
// Copy parent methods, then add new instance methods
// Or add new instance methods
} else {
- var mixins = members.__mixins__
- , statics = members.__static__
- ;
-
- if (mixins && hasOwn.call(members,'__mixins__'))
- mixin(NewClass, mixins);
-
- if (statics)
- core.descriptors( NewClass, core.filter(statics, notClassMagic) );
-
- core.descriptors( prototype, core.filter(members, notClassMagic) );
- // for (var k in members) {
- // if ( hasOwn.call(members,k) && classMagic.indexOf(k) === -1 )
- // setDesc(prototype, k, getDesc(members,k));
- // }
+ for (var k in members) {
+ if ( hasOwn.call(members,k) && classMagic.indexOf(k) === -1 )
+ setDesc(prototype, k, getDesc(members,k));
+ }
- NewClass.__super__ = SuperClass;
- prototype.constructor = prototype.__class__ = NewClass;
+ // NewClass.__super__ = SuperClass;
+ // prototype.constructor = prototype.__class__ = NewClass;
}
+ var mixins = members.__mixins__
+ , statics = members.__static__
+ ;
+
+ if (mixins && hasOwn.call(members,'__mixins__'))
+ mixin(NewClass, mixins);
+
+ if (statics)
+ for (var k in statics) {
+ if ( hasOwn.call(statics,k) && classMagic.indexOf(k) === -1 )
+ setDesc(NewClass, k, getDesc(statics,k));
+ }
+
// Notify parent of the subclass
ParentEmitter.fire('subclass',
var Y = require('Y').Y
+, mul = Y.op.curried.mul
,
// XXX: Speciated mixin must clone objects
},
+ tick : function tick(elapsed, now){
+
+ },
+
applyStatMods : function applyStatMods(modifier){
modifier = modifier || 1;
- Y(this.stat_mods).forEach(function(mod, name){
- var keyparts = name.split('_')
- , key = parts[0]
- , part = parts[1] || 'val'
- ;
- this.target.stats[key].modifyPart(part, modifier * mod);
- }, this);
+ Y(this.stat_mods).map(mul(modifier)).forEach(this._applyStatMod, this);
+ return this;
+ },
+
+ _applyStatMod : function _applyStatMod(mod, name){
+ var keyparts = name.split('_')
+ , key = keyparts[0]
+ , part = keyparts[1] || 'max'
+ ;
+ this.target.stats[key].modifyPart(part, mod);
return this;
},
var stats = Y({});
return stats
.extend.apply(stats, Y(arguments))
- .map(Stat.from);
+ .map(Stat.from)
+ .end();
};
, FRAME_RATE = 30
, MS_PER_FRAME = 1000 / FRAME_RATE
-, NOW = new Date().getTime() // Current tick's timestamp (ms)
+, NOW = 0 // Current tick's timestamp (ms)
, ELAPSED = MS_PER_FRAME // Time (ms) since previous tick
, TICKS = 0 // Ticks since start of game
, Rect = require('ezl/shape').Rect
+, Buff = require('tanks/effects/buff').Buff
, Thing = require('tanks/thing/thing').Thing
, Tank = require('tanks/thing/tank').Tank
, Item = require('tanks/thing/item').Item
this );
P =
- game.player = game.addThing(new PlayerTank(1), 5,9);
+ game.player = game.addThing(new PlayerTank(1), 3,9);
// game.addThing(new Tank(1).colors('#4596FF', '#182B53', '#F25522'), 3,9);
- E =
- game.addThing(new Tank(2), 0,7);
+ // E =
+ // game.addThing(new Tank(2), 0,7);
// game.addThing(new Tank(2), 1,0);
// game.addThing(new Tank(2), 8,1);
- I = game.addThing(new Item(), 8,8);
+ // I = game.addThing(new Item(), 8,8);
+
+ DATA = $('<pre id="data" style="position:absolute;top:0;left:0;width:200px;"></pre>').appendTo('body');
+ E = game.addThing(new Thing(2), 0,0);
+ var i = 0;
+ function testBulletSpeed(){
+ B = P.shoot(0,475);
+ var start = new Date().getTime()
+ , startClock = NOW
+ , startX = B.loc.x;
+ B.bounces = 1;
+ console.log(i+' B.movePerMs='+B.movePerMs+', move='+B.stats.move);
+
+ B.addEventListener('destroy', function(evt){
+ var elapsed = (new Date().getTime() - start)/1000
+ , clock = (NOW - startClock)/1000
+ , distance = startX - B.loc.x ;
+ DATA.text(DATA.text()+elapsed.toFixed(3)+'\t'+clock.toFixed(3)+'\t'+distance.toFixed(3)+'\t'+(distance/elapsed).toFixed(3)+'\n');
+ if (++i < 20) testBulletSpeed();
+ });
+ }
+ game.addEventListener('start', function(evt){
+ DATA.text('elapsed\tclock\tpx\tpx/s\n');
+ testBulletSpeed();
+ });
},
addWall : function addWall(x,y, w,h, isBoundary){
this.addEventListener('collide', this.onCollide.bind(this));
},
+ tick : function tick(elapsed, now){
+
+ },
+
activate : function activate(){
if (!this.owner) return;
},
}
this.updateMeta(evt);
- if (window.getSelection) {
- window.getSelection().removeAllRanges();
- }
+ // if (window.getSelection) {
+ // window.getSelection().removeAllRanges();
+ // }
return false;
},
}
this.updateMeta(evt);
- if (window.getSelection) {
- window.getSelection().removeAllRanges();
- }
+ // if (window.getSelection) {
+ // window.getSelection().removeAllRanges();
+ // }
return false;
},
// Attributes
stats : {
- hp : 1, // health
+ hp : 2, // health
move : 0.75, // move speed (squares/sec)
rotate : HALF_PI, // rotation speed (radians/sec)
power : 1, // attack power
'attr' : op.attr.methodize(),
get movePerMs(){
- var stat = this.stats.move;
- return (typeof stat === "number" ? stat : stat.val)*REF_SIZE/1000;
+ var stat = this.stats.move
+ , move = (typeof stat === "number" ? stat : stat.val);
+ var r = move*REF_SIZE/1000;
+ console.log(this+'.movePerMs = '+move+'*'+REF_SIZE+'/1000 = '+r);
+ return r;
},
},
createCooldowns : function createCooldowns(){
- this.cooldowns = {
+ this._cooldowns = Y({
'attack': new Cooldown(1000 * this.stats.speed.val)
- };
- this.ai = Y(this.ai).map(function(freq, k){
+ });
+ this._ai = Y(this.ai).map(function(freq, k){
return new Cooldown(1000 * freq);
});
- this._cooldowns = Y(this.cooldowns);
- this._ai = Y(this.ai);
+ this.cooldowns = this._cooldowns.end();
+ this.ai = this._ai.end();
},
updateCooldowns : function updateCooldowns(elapsed, now){
<script src="build/ezl/loop/fps.js" type="text/javascript"></script>
<script src="build/ezl/math/vec.js" type="text/javascript"></script>
<script src="build/ezl/loop/cooldown.js" type="text/javascript"></script>
-<script src="build/evt.js" type="text/javascript"></script>
<script src="build/ezl/loop/eventloop.js" type="text/javascript"></script>
+<script src="build/evt.js" type="text/javascript"></script>
<script src="build/ezl/loc/loc.js" type="text/javascript"></script>
<script src="build/ezl/math/line.js" type="text/javascript"></script>
<script src="build/ezl/math/rect.js" type="text/javascript"></script>
<script src="build/ezl/shape/circle.js" type="text/javascript"></script>
<script src="build/ezl/shape.js" type="text/javascript"></script>
<script src="build/ezl.js" type="text/javascript"></script>
-<script src="build/tanks/globals.js" type="text/javascript"></script>
<script src="build/jquery.hotkeys.js" type="text/javascript"></script>
+<script src="build/tanks/globals.js" type="text/javascript"></script>
<script src="build/Y/modules/y.kv.js" type="text/javascript"></script>
<script src="build/ezl/util/tree/binaryheap.js" type="text/javascript"></script>
<script src="build/ezl/util/tree/quadtree.js" type="text/javascript"></script>
+<script src="build/tanks/effects/buff.js" type="text/javascript"></script>
<script src="build/tanks/constants.js" type="text/javascript"></script>
<script src="build/Y/modules/y.scaffold.js" type="text/javascript"></script>
<script src="build/Y/modules/y.config.js" type="text/javascript"></script>