Commits

Anonymous committed d8ac1fd

center the target sequence

Comments (0)

Files changed (1)

     var createBallHolderModel = function(color) {
         var result = new THREE.Object3D();
         var material = new THREE.MeshLambertMaterial( {emissive:color, side:THREE.DoubleSide, transparent:true} );
-        material.opacity = 0.5;
+        material.opacity = 0.25;
 
         var mesh = new THREE.Mesh( new THREE.SphereGeometry( 2 ), material);
         result.add(mesh);
         var ball = createBallHolderModel( ballTypes[ballType] );
         ballHolders.push(ball);
         scene.add(ball);
-        ball.position.set( -15+5*(ballHolderPosition++), -14, 100 );
+        ball.position.set( leftMostCenter+5*(ballHolderPosition++), -14, 100 );
     }
 
     var clearBallHolders = function() {
         ballHolderPosition = 0;
     }
 
+    var leftMostCenter = -15;
     var ballPosition = 0;
     var addBall = function(ballType) {
         var ball = createBallModel( ballTypes[ballType] );
         balls.push(ball);
         scene.add(ball);
         var position = { x : 0, y: 0, z:200 };
-        var target = { x : -15+5*(ballPosition++), y: -14, z:100 };
+        var target = { x : leftMostCenter+5*(ballPosition++), y: -14, z:100 };
         var tween = new TWEEN.Tween(position).to(target, 500);
         tween.onUpdate( function(){
             ball.position.set( position.x, position.y, position.z );
         tween.start();
     }
 
+    var clearBalls = function() {
+        balls.forEach( function(object) {
+            scene.remove(object);
+        });
+        ballPosition = 0
+        state.length = 0;
+        objectiveIndex = 0;
+    }
+
     var state = [];
     var balls = [];
     var objectiveIndex = 0;
     var objective = undefined;
     var loadWorld = function(level) {
         clearBallHolders();
-        
-        balls.forEach( function(ball) { 
-            scene.remove(ball);
-        });
-        ballPosition = 0
-        state.length = 0;
-        objectiveIndex = 0;
+        clearBalls();
+        leftMostCenter = -((level.objective.length-1)*5)/2;
+
         objective = level.objective;
         objective.forEach( function(color) {
             addBallHolder(color);
         });
+
     }
 
     var updateObjective = function() {