changeset 12:2ecd16840900

added tracker
author Mason Green <mason.green@gmail.com>
date Sun, 22 Mar 2009 12:10:16 -0400
parents d998bf1b0654
children e1004697cae1
files ai.d main.d render.d ship.d steer.d urQuan.d
diffstat 6 files changed, 37 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ai.d	Sun Mar 22 09:35:24 2009 -0400
+++ b/ai.d	Sun Mar 22 12:10:16 2009 -0400
@@ -21,7 +21,7 @@
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LED TO,
  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
@@ -30,6 +30,10 @@
  */
 module openmelee.ai;
 
+import tango.io.Stdout : Stdout;
+import tango.math.Math : atan2;
+
+import blaze.common.bzMath: bzVec2;
 import openmelee.steer : Steer;
 import openmelee.ship : Ship;
 
@@ -38,7 +42,7 @@
 
 	Steer steer;
 	Ship ship;
-	float maxPredictionTime = 0;
+	float maxPredictionTime = 0.5f;
 	
 	this(Ship ship) {
 		this.ship = ship;
@@ -48,8 +52,17 @@
 	void move(Ship enemy) {
 	    
 	    steer.update();
-	    steer.steerForPursuit(enemy.state, maxPredictionTime);
-	    
+	    bzVec2 st;
+	    st = steer.steerForPursuit(enemy.state, maxPredictionTime);
+	    //ship.thrust();
+	    ship.state.target = st;
+        float angle = atan2(st.x, st.y);
+        
+        if(angle < 0) {
+            ship.turnLeft();
+        } else {
+            ship.turnRight();
+        }
     }
 
 }
--- a/main.d	Sun Mar 22 09:35:24 2009 -0400
+++ b/main.d	Sun Mar 22 12:10:16 2009 -0400
@@ -30,6 +30,8 @@
  */
 module openmelee.main;
 
+import tango.io.Stdout : Stdout;
+
 version(distrib) import tango.io.vfs.ZipFolder;
 import tango.time.StopWatch;
 import fc = tango.text.convert.Float : toString;
@@ -75,22 +77,24 @@
     StopWatch timer;
 
     jobHub.addRepeatableJob( {
+        // Update AI
+        ai.move(whut.ship1);
         // Update physics
         whut.world.step(timeStep, settings.velocityIterations,
                         settings.positionIterations);
-        // Update AI
-                
     }, ITERS_PER_SECOND);
 
     bool running = true;
 
     jobHub.addPreFrameJob( {
-        bzVec2 velocity = whut.ship1.rBody.linearVelocity;
+        whut.ship1.updateState();
+        whut.ship2.updateState();
         whut.ship1.limitVelocity();
         whut.ship2.limitVelocity();
     });
 
     jobHub.addPostFrameJob( {
+        whut.ship2.rBody.angularVelocity = 0.0f;
         gui.begin(cfg);
         gui.push(`main`);
         if (gui().getProperty!(bool)("frame.closeClicked")) {
--- a/render.d	Sun Mar 22 09:35:24 2009 -0400
+++ b/render.d	Sun Mar 22 12:10:16 2009 -0400
@@ -333,6 +333,11 @@
     gl.LoadIdentity();
     gl.Clear(GL_COLOR_BUFFER_BIT);
 
+    vec2 pp1 = vec2.from(ship2.rBody.position);
+    vec2 pp2 = vec2.from(ship2.state.target);
+    
+    gl.drawSegment(pp1, pp2, Color(0, 1, 0));
+    
     // Draw dynamic bodies
     if (settings.drawShapes) {
         for (bzBody b = world.bodyList; b; b = b.next) {
--- a/ship.d	Sun Mar 22 09:35:24 2009 -0400
+++ b/ship.d	Sun Mar 22 12:10:16 2009 -0400
@@ -48,6 +48,7 @@
     bzVec2 up;
     bzVec2 side;
     bzVec2 forward;
+    bzVec2 target;
 	float speed = 0;
 	float maxForce = 0;
 	
--- a/steer.d	Sun Mar 22 09:35:24 2009 -0400
+++ b/steer.d	Sun Mar 22 12:10:16 2009 -0400
@@ -56,6 +56,7 @@
         m_velocity = m_ship.state.velocity;
         m_speed = m_ship.state.speed;
         m_maxForce = m_ship.state.maxForce;
+        m_forward = m_ship.state.forward;
     }
 
     // -------------------------------------------------- steering behaviors
@@ -393,7 +394,7 @@
         // estimated position of quarry at intercept
         bzVec2 target = quarry.predictFuturePosition(etl);
 
-        return steerForSeek (target);
+        return target; //steerForSeek (target);
     }
 
     // ------------------------------------------------------------------------
--- a/urQuan.d	Sun Mar 22 09:35:24 2009 -0400
+++ b/urQuan.d	Sun Mar 22 12:10:16 2009 -0400
@@ -47,6 +47,11 @@
     this(bzWorld world) {
 
         super(world);
+        engineForce = bzVec2(500, 0);
+        turnForce = bzVec2(0, 5000);
+        rightTurnPoint = bzVec2(-0.5, 0);
+        leftTurnPoint = bzVec2(0.5, 0);
+        
         auto bodyDef = new bzBodyDef;
         //bodyDef.isBullet = true;
         bodyDef.position = bzVec2(10,5);