diff melee.d @ 5:6f455ef24063

fixed world wrap
author zzzzrrr <mason.green@gmail.com>
date Sat, 21 Mar 2009 15:51:41 -0400
parents 8d7c50415269
children eb6059f7035a
line wrap: on
line diff
--- a/melee.d	Fri Mar 20 17:00:30 2009 -0400
+++ b/melee.d	Sat Mar 21 15:51:41 2009 -0400
@@ -29,6 +29,8 @@
  */
 module openmelee.melee;
 
+import tango.io.Stdout: Stdout;
+
 import Integer = tango.text.convert.Integer;
 import tango.math.Math;
 import tango.math.random.Kiss;
@@ -95,7 +97,7 @@
     bool drawJoints = true;
     bool drawControllers;
     bool drawCoreShapes;
-    bool drawAABBs = true;
+    bool drawAABBs;
     bool drawOBBs;
     bool drawPairs;
     bool drawContactPoints;
@@ -158,12 +160,12 @@
 	this(Settings *settings)
 	{
 		this.settings = settings;
-		init();
 		spawnRect = vec2(INIT_SPAWN_SIZE, INIT_SPAWN_SIZE);
 		// bzWorld boundary callback
 		m_boundaryListener = new BoundaryListener(this);
 		// bzContact callback
 		m_contactListener = new ContactListener(this);
+        init();
 	}
 
 	void init() {
@@ -190,34 +192,37 @@
 
 	EventHandling onKey(KeyboardEvent e)
 	{
-		if (e.unicode == '+') {         // HACK: the windows input writer doesn't do plus correctly yet   - h3
-			e.keySym = KeySym.plus;
-		}
+        // Key pressed
 		if (e.down) {
 			switch (e.keySym) {
+            case KeySym.space:
+                settings.drawAABBs = !settings.drawAABBs;
+                break;
 			case KeySym.Escape:
                 quit = true;
                 break;
+            case KeySym.Up:            
+                thrust = true;
+                break;
+            case KeySym.Left:            
+                ship1.turnLeft();
+                break;
+            case KeySym.Right:             
+                ship1.turnRight();
+                break;
+            case KeySym.Down:             
+                break;
 			default:
-			    char key = cast(char) e.keySym;
-			    if(key == 'w') {
-			        thrust = true;
-			        break;
-			    } else {
-			        ship1.turn(key);
-			    }
 				break;
 			}
         // Key released
 		} else {
-		    char key = cast(char) e.keySym;
-		    if(key == 'w') {
+		    if(e.keySym == KeySym.Up) {
 		         thrust = false;
-		    } else if (key == 'd' || key == 'a') {
+		    } else if (e.keySym == KeySym.Left || e.keySym == KeySym.Right) {
                 ship1.rBody.angularVelocity = 0.0f;
             }
 		}
-
 		return EventHandling.Stop;
 	}
 
@@ -266,8 +271,21 @@
 
 	void boundaryViolated(bzBody rBody)
 	{
-        uint key = rBody.toHash();
-        wrapList[key] = rBody;
+        float x,y;
+        
+        if(rBody.position.x > worldAABB.upperBound.x) {
+            x = worldAABB.lowerBound.x + 5;
+            rBody.position = bzVec2(x, rBody.position.y);
+        } else if (rBody.position.x < worldAABB.lowerBound.x) {
+            x = worldAABB.upperBound.x - 5;
+            rBody.position = bzVec2(x, rBody.position.y);
+        } else if (rBody.position.y > worldAABB.upperBound.y) {
+            y = worldAABB.lowerBound.y + 5;
+            rBody.position = bzVec2(rBody.position.x, y);
+        } else if(rBody.position.y < worldAABB.lowerBound.y) {
+            y = worldAABB.upperBound.y - 5;
+            rBody.position = bzVec2(rBody.position.x, y);
+        }
 	}
 
 	bool quit;
@@ -276,7 +294,6 @@
 	float zoom = 40;
 	int pointCount;
 	vec2 viewCenter;
-    bzBody[uint] wrapList;
 
 	bzWorld world;
 	Settings *settings;