Commits

abrie  committed 60418f4

add next() and previous() level navigators

  • Participants
  • Parent commits 8144700

Comments (0)

Files changed (2)

File application.js

     }
 
     var currentLevelData = undefined;
-    var load = function(jsonLevelData) {
-        currentLevelData = jsonLevelData;
+    var load = function(levelData) {
+        currentLevelData = levelData;
         var level = JSON.parse(currentLevelData);
         space2d.loadWorld(level);
         space3d.loadWorld(level);
         editor2d.loadWorld(level);
     }
 
+    var currentLevelNumber = -1;
+    var next = function() {
+        currentLevelNumber++;
+        load( levels.get(currentLevelNumber) );
+    }
+
+    var previous = function() {
+        currentLevelNumber = --currentLevelNumber < 0 ? 0 : currentLevelNumber;
+        load( levels.get(currentLevelNumber) );
+    }
+
     var objectiveHandler = function(success) {
         console.log("objective success?:",success);
     }
 
-    var levelLoader = {load:load, restart:restart};
+    var levelLoader = {load:load, restart:restart, next:next, previous:previous};
     editor2d.setLevelLoader( levelLoader );
     space2d.setObjectiveDelegate( objectiveHandler );
     space3d.setObjectiveDelegate( objectiveHandler );
             editor2d.draw();
         }
 
-        var loadLevel = function() {
-        }
-
         function tick(params) {
             update(1/params.delta);
             render();
         createjs.Ticker.useRAF = true;
         createjs.Ticker.setFPS(30);
         createjs.Ticker.addEventListener("tick", tick);
-        load(levels.level1);
+        next();
     }
 
     video.videoCamera.waitForAuthorization( go );
 
 define([],function() {
 
-    var level1 = '{"structure":[{"isBall":true,"ballType":"red","x":-7.961538791656494,"y":2.500000238418579},{"isBall":true,"ballType":"green","x":8.115384101867676,"y":-2.346153736114502},{"warpHoleId":2,"isWarpHole":true,"isOpen":false,"x":-7.730769157409668,"y":-5.730769157409668},{"warpHoleId":8,"isWarpHole":true,"isOpen":false,"x":-0.038461796939373016,"y":0.8846151828765869},{"isGround":true,"x":-0.05769229307770729,"y":0.4615384340286255,"x1":8.134615384615383,"y1":-1.5384615384615385,"x2":-8.134615384615383,"y2":1.5384615384615385},{"isGround":true,"x":0.26923078298568726,"y":-4.480769157409668,"x1":-8.192307692307693,"y1":-1.6730769230769234,"x2":8.192307692307693,"y2":1.6730769230769234}],"objective":["red","green"]}';
+    var stack = [];
+    stack.push('{"structure":[{"isBall":true,"ballType":"red","x":-7.961538791656494,"y":2.500000238418579},{"isBall":true,"ballType":"green","x":8.115384101867676,"y":-2.346153736114502},{"warpHoleId":2,"isWarpHole":true,"isOpen":false,"x":-7.730769157409668,"y":-5.730769157409668},{"warpHoleId":8,"isWarpHole":true,"isOpen":false,"x":-0.038461796939373016,"y":0.8846151828765869},{"isGround":true,"x":-0.05769229307770729,"y":0.4615384340286255,"x1":8.134615384615383,"y1":-1.5384615384615385,"x2":-8.134615384615383,"y2":1.5384615384615385},{"isGround":true,"x":0.26923078298568726,"y":-4.480769157409668,"x1":-8.192307692307693,"y1":-1.6730769230769234,"x2":8.192307692307693,"y2":1.6730769230769234}],"objective":["red","green"]}');
 
     return {
-        level1:level1,
+        get: function(index) { return stack[index]; }
     }
 });