diff ship.d @ 11:d998bf1b0654

Added utilities and AI; fixed steer
author Mason Green <mason.green@gmail.com>
date Sun, 22 Mar 2009 09:35:24 -0400
parents 4ee9e4a0c03b
children 2ecd16840900
line wrap: on
line diff
--- a/ship.d	Sun Mar 22 08:03:43 2009 -0400
+++ b/ship.d	Sun Mar 22 09:35:24 2009 -0400
@@ -41,6 +41,21 @@
 
 alias LinkedList!(bzShape) ShapeList;
 
+struct State 
+{
+	bzVec2 position;
+    bzVec2 velocity;
+    bzVec2 up;
+    bzVec2 side;
+    bzVec2 forward;
+	float speed = 0;
+	float maxForce = 0;
+	
+	bzVec2 predictFuturePosition(float dt) {
+	    return (position + velocity * dt);
+    }
+}
+
 abstract class Ship
 {
     bzWorld world;
@@ -50,7 +65,8 @@
     bzVec2 turnForce;
     bzVec2 leftTurnPoint;
     bzVec2 rightTurnPoint;
-
+	State state;
+	
     float maxLinVel = 100;
     float maxAngVel = 2;
     
@@ -78,7 +94,6 @@
     }
     
     void setGravity() {
-        
         float minRadius = 0.1;
         float maxRadius = 10;
         float strength = 3.5;
@@ -88,7 +103,6 @@
     }
     
     void limitVelocity() {
-        
         float vx = rBody.linearVelocity.x;
         float vy = rBody.linearVelocity.y;
         float av = rBody.angularVelocity;
@@ -96,4 +110,14 @@
         rBody.linearVelocity.y = bzClamp(vy, -maxLinVel, maxLinVel);
         rBody.angularVelocity = bzClamp(av, -maxAngVel, maxAngVel);
     }
+    
+    void updateState() {
+    	state.velocity = rBody.linearVelocity;
+    	state.speed = state.velocity.length;
+    	state.position = rBody.position;
+    	bzVec2 heading = engineForce.rotate(rBody.angle);
+    	heading.normalize();
+    	state.forward = heading;
+    }
+    
 }