diff --git a/unpublishedScripts/DomainContent/Home/tiltMaze/createTiltMaze.js b/unpublishedScripts/DomainContent/Home/tiltMaze/createTiltMaze.js index f1228e5280..24dbd7d5bb 100644 --- a/unpublishedScripts/DomainContent/Home/tiltMaze/createTiltMaze.js +++ b/unpublishedScripts/DomainContent/Home/tiltMaze/createTiltMaze.js @@ -5,6 +5,7 @@ // Created by James B. Pollack @imgntn on 2/15/2016 // Copyright 2016 High Fidelity, Inc. // +// This script creates a maze with a ball that you can tilt to try to get to the end! // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -28,31 +29,31 @@ var BALL_DIMENSIONS = Vec3.multiply(SCALE, { x: 0.035, y: 0.035, z: 0.035 -}) +}); var BALL_SPAWNER_DIMENSIONS = Vec3.multiply(SCALE, { x: 0.05, y: 0.05, z: 0.05 -}) +}); var BALL_DETECTOR_DIMENSIONS = Vec3.multiply(SCALE, { x: 0.1, y: 0.1, z: 0.1 -}) +}); var BALL_COLOR = { red: 255, green: 0, blue: 0 -} +}; var DEBUG_COLOR = { red: 0, green: 255, blue: 0 -} +}; var center = Vec3.sum(Vec3.sum(MyAvatar.position, { x: 0, @@ -116,7 +117,7 @@ var getBallStartLocation = function() { finalOffset = Vec3.sum(finalOffset, Vec3.multiply(front, BALL_FORWARD_OFFSET)); var location = Vec3.sum(mazeProps.position, finalOffset); return location; -} +}; var getBallFinishLocation = function() { var mazeProps = Entities.getEntityProperties(tiltMaze); @@ -129,12 +130,10 @@ var getBallFinishLocation = function() { position = Vec3.sum(position, Vec3.multiply(forward, DETECTOR_FORWARD_OFFSET)); return position; -} +}; var createBall = function(position) { - - print('making ball') var properties = { name: 'Hifi Tilt Maze Ball', type: 'Sphere', @@ -174,7 +173,7 @@ var createBallSpawningAnchor = function() { }; ballSpawningAnchor = Entities.addEntity(properties); -} +}; var createBallDetector = function() { @@ -212,9 +211,9 @@ var createTiltMaze = function(position) { script: MAZE_SCRIPT } - tiltMaze = Entities.addEntity(properties) + tiltMaze = Entities.addEntity(properties); -} +}; var createLightAtTheEnd = function() { @@ -223,7 +222,7 @@ var createLightAtTheEnd = function() { var up = Quat.getUp(mazeProps.rotation); var down = Vec3.multiply(-1, up); - var emitOrientation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, down) + var emitOrientation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, down); var position = getBallFinishLocation(); var lightProperties = { @@ -242,7 +241,7 @@ var createLightAtTheEnd = function() { }; lightAtTheEnd = Entities.addEntity(lightProperties); -} +}; var createAll = function() { createTiltMaze(center); @@ -260,7 +259,7 @@ var createAll = function() { } }) }) -} +}; createAll(); diff --git a/unpublishedScripts/DomainContent/Home/tiltMaze/maze.js b/unpublishedScripts/DomainContent/Home/tiltMaze/maze.js index 931f36ab8b..557861ba30 100644 --- a/unpublishedScripts/DomainContent/Home/tiltMaze/maze.js +++ b/unpublishedScripts/DomainContent/Home/tiltMaze/maze.js @@ -1,17 +1,16 @@ // // maze.js // -// Script Type: Entity // // Created by James B. Pollack @imgntn on 2/15/2016 // Copyright 2016 High Fidelity, Inc. // -// // This script resets a ball to its original position when the ball enters it. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + (function() { Script.include('../../../../libraries/utils.js'); @@ -41,13 +40,13 @@ x: 0.05, y: 0.05, z: 0.05 - }) + }); var BALL_COLOR = { red: 255, green: 0, blue: 0 - } + }; var _this; @@ -97,7 +96,7 @@ if (this.ballLocked === true) { return; } - // print('making ball') + var properties = { name: 'Hifi Tilt Maze Ball', type: 'Sphere', @@ -112,18 +111,17 @@ density: BALL_DENSITY, color: BALL_COLOR, dimensions: BALL_DIMENSIONS - }; this.ball = Entities.addEntity(properties); }, destroyBall: function() { - var res = Entities.findEntities(MyAvatar.position, 10); - res.forEach(function(r) { - var props = Entities.getEntityProperties(r, ['name']); + var results = Entities.findEntities(MyAvatar.position, 10); + results.forEach(function(result) { + var props = Entities.getEntityProperties(result, ['name']); var isAMazeBall = props.name.indexOf('Maze Ball'); - if (isAMazeBall > -1 && r === _this.ball) { - Entities.deleteEntity(r); + if (isAMazeBall > -1 && result === _this.ball) { + Entities.deleteEntity(result); } }) }, @@ -131,40 +129,34 @@ if (this.ballLocked === true) { return; } - // print('test ball distance') + var userData = Entities.getEntityProperties(this.entityID, 'userData').userData; var data = null; try { - data = JSON.parse(userData) + data = JSON.parse(userData); } catch (e) { - print('error parsing json in maze userdata') + // print('error parsing json in maze userdata') } if (data === null) { - print('data is null in userData') + // print('data is null in userData') return; } - // print('DATA IS:'+JSON.stringify(data)) - var ballPosition; if (this.ball === null) { this.ball = data.tiltMaze.firstBall; ballPosition = Entities.getEntityProperties(data.tiltMaze.firstBall, 'position').position; } else { - ballPosition = Entities.getEntityProperties(this.ball, 'position').position + ballPosition = Entities.getEntityProperties(this.ball, 'position').position; } var ballSpawnerPosition = Entities.getEntityProperties(data.tiltMaze.ballSpawner, 'position').position; var separation = Vec3.distance(ballPosition, ballSpawnerPosition); - // print('separation from ball:' + separation) if (separation > BALL_DISTANCE_THRESHOLD) { - // print('BALL TOO FAR MAKE A NEW ONE') this.destroyBall(); this.createBall(); - } else { - } }, testWinDistance: function() { @@ -175,12 +167,12 @@ var userData = Entities.getEntityProperties(this.entityID, 'userData').userData; var data = null; try { - data = JSON.parse(userData) + data = JSON.parse(userData); } catch (e) { - print('error parsing json in maze userdata') + // print('error parsing json in maze userdata') } if (data === null) { - print('data is null in userData') + // print('data is null in userData') return; } @@ -189,25 +181,20 @@ this.ball = data.tiltMaze.firstBall; ballPosition = Entities.getEntityProperties(data.tiltMaze.firstBall, 'position').position; } else { - ballPosition = Entities.getEntityProperties(this.ball, 'position').position + ballPosition = Entities.getEntityProperties(this.ball, 'position').position; } var ballDetectorPosition = Entities.getEntityProperties(data.tiltMaze.detector, 'position').position; var separation = Vec3.distance(ballPosition, ballDetectorPosition); - // print('separation from win:' + separation) if (separation < BALL_DETECTOR_THRESHOLD) { - // print('BALL IS IN DETECTOR, MAKE A NEW ONE') this.ballLocked = true; this.destroyBall(); this.playVictorySound(); Script.setTimeout(function() { _this.ballLocked = false; - _this.createBall() + _this.createBall(); }, 1500) - } else { - - } - + } }, playVictorySound: function() { var position = Entities.getEntityProperties(this.entityID, "position").position;