Fixes tank AI movement.
authordsc <david.schoonover@gmail.com>
Fri, 19 Nov 2010 00:07:13 +0000 (16:07 -0800)
committerdsc <david.schoonover@gmail.com>
Fri, 19 Nov 2010 00:07:13 +0000 (16:07 -0800)
css/lttl.css
src/tanks/thing/tank.js
src/tanks/thing/thing.js

index 72ee86a..ee4764c 100644 (file)
@@ -1,6 +1,6 @@
 html, body { width:100%; height:100%; 
-    font-family:Geogrotesque,Helvetica; color:#fff; background-color:#3F3F3F; }
-body { font-family:Geogrotesque, Helvetica; font-size:12pt; }
+    font-family:Geogrotesque,Helvetica; font-size:12pt; color:#fff;
+    background-color:#3F3F3F; }
 h1 { position:fixed; top:0; right:0; margin:0; padding:0; font-size:3em; color:#000; opacity:0.25; z-index:100; }
 h2, h3, h4, h5 { margin:0; margin-bottom:0.5em; }
 ul, ol, li { list-style: none ! important; margin:0; padding:0; }
@@ -25,7 +25,7 @@ ul, ol, li { list-style: none ! important; margin:0; padding:0; }
     #info .sep { opacity:0.1; background-color:#999; margin:5px 0; height:1px; }
     #info .fps-sparkline { width:100%; height:1.5em; margin-top:0.5em; }
 
-#notes { position:fixed; top:4em; right:1em; color:#BFBFBF; }
+#notes { position:fixed; top:4em; right:1em; color:#BFBFBF; width:300px; }
     #notes ul, #notes ol, #notes li { list-style:circle ! important; }
     #notes li { margin-left:1em; }
 
index 064ff18..0add167 100644 (file)
@@ -20,7 +20,7 @@ Tank = Thing.subclass('Tank', {
         rotate    : HALF_PI,    // rotation speed (radians/sec)
         
         power     : 1,          // attack power
-        speed     : 0.75,       // attack cool (sec)
+        speed     : 1,          // attack cool (sec)
         shots     : 5           // max projectiles in the air at once
     },
     
@@ -58,8 +58,11 @@ Tank = Thing.subclass('Tank', {
         }
         
         // Nothing to shoot at? Move toward something
-        var t = this.nearLike(10000, 'Y.is(Tank, _) && _.align !== '+this.align).shift();
+        var t = this.nearLike(10000, 'Y.is(Tank, _) && _.align !== '+this.align)
+                    .remove(this)
+                    .shift();
         if (t) {
+            // console.log(this, 'moving toward', t);
             this.move(t.loc.x, t.loc.y);
             return this;
         }
@@ -162,13 +165,8 @@ Tank = Thing.subclass('Tank', {
     },
     
     rotateBarrel : function rotateBarrel(x,y){
-        var bb = this.boundingBox
-        ,   w = this.width, h = this.height
-        ,   x0 = x - bb.x1 - w/2
-        ,   y0 = y - bb.y1 - h/2
-        ,   theta = Math.atan2(y0,x0)
-        ;
-        this.barrel.rotate(theta);
+        this.barrel.rotate(this.angleTo(x,y));
+        return this;
     },
     
     rotateBarrelRelPage : function rotateBarrelRelPage(pageX, pageY){
@@ -180,6 +178,7 @@ Tank = Thing.subclass('Tank', {
         ,   theta = Math.atan2(-y,-x)
         ;
         this.barrel.rotate(theta);
+        return this;
     }
     
 });
index bbc6218..0177d53 100644 (file)
@@ -102,21 +102,29 @@ Thing = new Evt.Class('Thing', {
         this._cooldowns = Y(cs);
     },
     
+    updateCooldowns : function updateCooldowns(){
+        this._cooldowns.invoke('update', NOW);
+        return this;
+    },
+    
     /**
      * Calculates the location of the bullet-spawning point on this Thing.
      */
     getTurretLoc : function getTurretLoc(){ return this.loc; },
     
+    angleTo : function angleTo(x,y){
+        var bb = this.boundingBox
+        ,   w = this.width, h = this.height
+        ,   x0 = x - bb.x1 - w/2
+        ,   y0 = y - bb.y1 - h/2
+        ;
+        return Math.atan2(y0,x0);
+    },
     
     
     
     // *** Gameplay Methods *** //
     
-    updateCooldowns : function updateCooldowns(){
-        this._cooldowns.invoke('update', NOW);
-        return this;
-    },
-    
     /**
      * Determines what the creep should do -- move, attack, etc.
      */
@@ -125,7 +133,7 @@ Thing = new Evt.Class('Thing', {
     },
     
     move : function move(x,y){
-        return this.moveByAngle(Math.atan2(-y,-x));
+        return this.moveByAngle( this.angleTo(x,y) );
     },
     
     moveByAngle : function moveByAngle(theta){