Found bullet-speed bug. Descriptors were not being copied correctly, so I suppose...
authordsc <david.schoonover@gmail.com>
Sun, 2 Jan 2011 01:06:50 +0000 (17:06 -0800)
committerdsc <david.schoonover@gmail.com>
Sun, 2 Jan 2011 01:06:50 +0000 (17:06 -0800)
13 files changed:
src/Y/class.cjs
src/Y/types/object.cjs
src/Y/utils.cjs
src/evt.cjs
src/tanks/effects/buff.cjs
src/tanks/effects/stat.cjs
src/tanks/globals.js
src/tanks/map/level.cjs
src/tanks/thing/item.cjs
src/tanks/thing/player.cjs
src/tanks/thing/tank.cjs
src/tanks/thing/thing.cjs
www/deps.html

index 683f032..b8bf9e9 100644 (file)
@@ -22,6 +22,7 @@ var type       = require('Y/type')
 
 ,   KNOWN_CLASSES = type.type.KNOWN_CLASSES
 ,   classToString = function toString(){ return this.className+"()"; }
+,   classStatics  = [ 'instantiate', 'fabricate', 'subclass' ]
 ;
 
 /**
@@ -107,8 +108,10 @@ function Class(className, Parent, members) {
     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)
index b06d0e3..860597c 100644 (file)
@@ -153,7 +153,7 @@ YCollection.subclass('YObject', {
         ;
         for ( var name in o )
             acc[name] = fn.call(cxt, o[name], name, o);
-        return acc;
+        return Y(acc);
     },
     
     'forEach' : function forEach( fn, context ){
@@ -168,7 +168,7 @@ YCollection.subclass('YObject', {
         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 ){
index 0f01984..a20ad09 100644 (file)
@@ -24,7 +24,7 @@ function bindAll(o, names){
         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;
index c4850d2..100a51a 100644 (file)
@@ -42,6 +42,7 @@ var Y       = require('Y').Y
 ,   classToString = function toString(){ return this.className+"()"; }
 ,   classMagic    = [ '__static__', '__mixins__', '__emitter__', '__bases__', '__initialise__' ]
 ,   mixinSkip     = [ '__mixin_skip__', 'onMixin', 'onInit', 'init' ].concat(classMagic)
+,   classStatics  = [ 'instantiate', 'fabricate', 'subclass' ]
 ,
 
 
@@ -188,10 +189,9 @@ function Class(className, Parent, members){
     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
@@ -228,26 +228,28 @@ function Class(className, Parent, members){
     
     // 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',
index 83d276f..c7253dd 100644 (file)
@@ -1,4 +1,5 @@
 var Y = require('Y').Y
+,   mul = Y.op.curried.mul
 ,
 
 
@@ -36,15 +37,22 @@ Y.subclass('Buff', {
         // 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;
     },
     
index 8b3ede7..33ec019 100644 (file)
@@ -123,5 +123,6 @@ function createStats(o){
     var stats = Y({});
     return stats
         .extend.apply(stats, Y(arguments))
-        .map(Stat.from);
+        .map(Stat.from)
+        .end();
 };
index b3863ba..b03d4be 100644 (file)
@@ -15,7 +15,7 @@ var undefined
 ,   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
 
index 4f3beaa..2877b92 100644 (file)
@@ -3,6 +3,7 @@ var Y          = require('Y').Y
 
 ,   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
@@ -41,15 +42,39 @@ Rect.subclass('Level', {
             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){
index 59da3b9..6055a4f 100644 (file)
@@ -57,6 +57,10 @@ Thing.subclass('Item', {
         this.addEventListener('collide', this.onCollide.bind(this));
     },
     
+    tick : function tick(elapsed, now){
+        
+    },
+    
     activate : function activate(){
         if (!this.owner) return;
     },
index 859f2eb..f81c604 100644 (file)
@@ -148,9 +148,9 @@ Tank.subclass('PlayerTank', {
         }
         this.updateMeta(evt);
         
-        if (window.getSelection) {
-            window.getSelection().removeAllRanges();
-        }
+        // if (window.getSelection) {
+        //     window.getSelection().removeAllRanges();
+        // }
         
         return false;
     },
@@ -165,9 +165,9 @@ Tank.subclass('PlayerTank', {
         }
         this.updateMeta(evt);
         
-        if (window.getSelection) {
-            window.getSelection().removeAllRanges();
-        }
+        // if (window.getSelection) {
+        //     window.getSelection().removeAllRanges();
+        // }
         
         return false;
     },
index d2d4163..bc9199d 100644 (file)
@@ -38,7 +38,7 @@ Thing.subclass('Tank', function(Tank){
         
         // 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
index e4c4525..b82b7d0 100644 (file)
@@ -93,8 +93,11 @@ exports['Thing'] = new evt.Class('Thing', {
     '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;
     },
     
     
@@ -122,15 +125,15 @@ exports['Thing'] = new evt.Class('Thing', {
     },
     
     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){
index f1ca947..a8d24b2 100644 (file)
@@ -24,8 +24,8 @@
 <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>