Commits

Anonymous committed e8617bc

add clear button coupled to helper function for emtpying world

Comments (0)

Files changed (3)

         <input type="checkbox" id="pause">pause</input>
         <button id="reload">reload</button>
         <button id="serialize">serialize</button>
+        <button id="clear">clear</button>
+        <button id="next">next</button>
+        <button id="previous">previous</button>
         <input type="text" id="objective"></input>
     </div>
     <div id="subsystem"></div>
     document.getElementById("mode").onchange = function() { mode = this.options[this.selectedIndex].value; }
     document.getElementById("pause").onclick = function() { space2d.setPause(this.checked); }
     document.getElementById("reload").onclick = function() { levelLoader.restart(); }
+    document.getElementById("clear").onclick = function() { space2d.clearWorld(); }
     document.getElementById("serialize").onclick = function() { levelLoader.load( iterateBodies() ); }
+    document.getElementById("next").onclick = function() { levelLoader.next(); }
+    document.getElementById("previous").onclick = function() { levelLoader.previous(); }
 
     var iterateBodies = function() {
         var bodyList = space2d.getWorld().GetBodyList();
         while(bodyList.a != 0) {
             if( bodyList.userData ) {
                 var attributes = bodyList.userData.attributes;
-                var worldCenter = bodyList.GetWorldCenter();
-                attributes.x = worldCenter.get_x();
-                attributes.y = worldCenter.get_y();
-                structure.push( bodyList.userData.attributes );
+                if( !attributes.isWall ) {
+                    var worldCenter = bodyList.GetWorldCenter();
+                    attributes.x = worldCenter.get_x();
+                    attributes.y = worldCenter.get_y();
+                    structure.push( bodyList.userData.attributes );
+                }
             }
             bodyList = bodyList.GetNext();
         }
         return world;
     }
 
-
     var loadWorld = function(level) {
-        world = newWorld();
-        createWall(0,-6.7,18,0);
-        createWall(0,6.7,18,0);
-        createWall(9,0,0,13.4);
-        createWall(-9,0,0,-13.4);
+        clearWorld();
         level.structure.forEach( function(object) {
             if( object.isBall ) {
                 createBall(object.ballType, object.x, object.y);
         });
     }
 
+    var clearWorld = function() {
+        world = newWorld();
+        createWall(0,-6.7,18,0);
+        createWall(0,6.7,18,0);
+        createWall(9,0,0,13.4);
+        createWall(-9,0,0,-13.4);
+    }
+
     var fixtureToUserData = function(f) {
         var userData = f.GetBody().userData;
         return userData ? userData : {};
         loadWorld: loadWorld,
         setPause: setPause,
         getWorld: function() { return world; },
+        clearWorld: clearWorld,
         createBall: createBall,
         setObjectiveDelegate: function(delegate) { notifyObjective = delegate; },
     }