diff --git a/examples/color_busters_game/createColorBusterCubes.js b/examples/color_busters_game/createColorBusterCubes.js deleted file mode 100644 index 2bc14e5a01..0000000000 --- a/examples/color_busters_game/createColorBusterCubes.js +++ /dev/null @@ -1,89 +0,0 @@ -var CUBE_DIMENSIONS = { - x: 1, - y: 1, - z: 1 -}; - -var NUMBER_OF_CUBES_PER_SIDE= 20; - -var STARTING_CORNER_POSITION = { - x: 0, - y: 0, - z: 0 -} - -var STARTING_COLORS = [ - ['red', { - red: 255, - green: 0, - blue: 0 - }], - ['yellow', { - red: 255, - green: 255, - blue: 0 - }], - ['blue', { - red: 0, - green: 0, - blue: 255 - }], - ['orange', { - red: 255, - green: 165, - blue: 0 - }], - ['violet', { - red: 128, - green: 0, - blue: 128 - }], - ['green', { - red: 0, - green: 255, - blue: 0 - }] -] - -function chooseStartingColor() { - var startingColor = STARTING_COLORS[Math.floor(Math.random() * STARTING_COLORS.length)]; - return startingColor -} - -function createColorBusterCube(row, column, vertical) { - - var startingColor = chooseStartingColor(); - var colorBusterCubeProperties = { - name: 'Hifi-ColorBusterWand', - type: 'Model', - url: COLOR_WAND_MODEL_URL, - dimensions: COLOR_WAND_DIMENSIONS, - position: { - x: row, - y: vertical, - z: column - }, - userData: JSON.stringify({ - hifiColorBusterCubeKey: { - originalColorName: startingColor[0], - - } - }) - }; - - return Entities.addEntity(colorBusterCubeProperties); -} - -function createBoard() { - var vertical; - for (vertical = 0; vertical === NUMBER_OF_CUBES_PER_SIDE;vertical++) { - var row; - var column; - //create a single layer - for (row = 0; row === NUMBER_OF_CUBES_PER_SIDE; row++) { - for (column = 0; column === NUMBER_OF_CUBES_PER_SIDE; column++) { - this.createColorBusterCube(row, column, vertical) - } - } - } -} \ No newline at end of file diff --git a/examples/color_busters_game/createColorBusterWand.js b/examples/color_busters_game/createColorBusterWand.js deleted file mode 100644 index 4af5306177..0000000000 --- a/examples/color_busters_game/createColorBusterWand.js +++ /dev/null @@ -1,55 +0,0 @@ -var COLOR_WAND_MODEL_URL = ''; -var COLOR_WAND_DIMENSIONS = { - x: 0, - y: 0, - z: 0 -}; -var COLOR_WAND_START_POSITION = { - x: 0, - y: 0, - z: 0 -}; -var STARTING_COLORS = [ - ['red', { - red: 255, - green: 0, - blue: 0 - }], - ['yellow', { - red: 255, - green: 255, - blue: 0 - }], - ['blue', { - red: 0, - green: 0, - blue: 255 - }] -] - -function chooseStartingColor() { - var startingColor = STARTING_COLORS[Math.floor(Math.random() * STARTING_COLORS.length)]; - return startingColor -} - -function createColorBusterWand() { - - var startingColor = chooseStartingColor(); - var colorBusterWandProperties = { - name: 'Hifi-ColorBusterWand', - type: 'Model', - url: COLOR_WAND_MODEL_URL, - dimensions: COLOR_WAND_DIMENSIONS, - position: COLOR_WAND_START_POSITION, - userData: JSON.stringify({ - hifiColorBusterWandKey: { - owner: MyAvatar.sessionUUID, - currentColor: startingColor[1], - originalColorName: startingColor[0], - colorLocked: false - } - }) - }; - - Entities.addEntity(colorBusterWandProperties); -} \ No newline at end of file diff --git a/examples/color_busters_game/colorBusterWand.js b/examples/example/games/color_busters/colorBusterWand.js similarity index 69% rename from examples/color_busters_game/colorBusterWand.js rename to examples/example/games/color_busters/colorBusterWand.js index 26948da91b..6080d6f345 100644 --- a/examples/color_busters_game/colorBusterWand.js +++ b/examples/example/games/color_busters/colorBusterWand.js @@ -1,42 +1,63 @@ +// +// colorBusterWand.js +// +// Created by James B. Pollack @imgntn on 11/2/2015 +// Copyright 2015 High Fidelity, Inc. +// +// This is the entity script that attaches to a wand for the Color Busters game +// +// 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"); - //seconds that the combination lasts - var COMBINED_COLOR_DURATION = 10; + var COMBINED_COLOR_DURATION = 5; - var INDICATOR_OFFSET_UP = 0.5; + var INDICATOR_OFFSET_UP = 0.40; - var REMOVE_CUBE_SOUND_URL = ''; - var COMBINE_COLORS_SOUND_URL = ''; + var REMOVE_CUBE_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/color_busters/boop.wav'; + var COMBINE_COLORS_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/color_busters/powerup.wav'; + + var COLOR_INDICATOR_DIMENSIONS = { + x: 0.10, + y: 0.10, + z: 0.10 + }; var _this; - function ColorWand() { + function ColorBusterWand() { _this = this; - }; + } ColorBusterWand.prototype = { combinedColorsTimer: null, - + soundIsPlaying: false, preload: function(entityID) { print("preload"); this.entityID = entityID; this.REMOVE_CUBE_SOUND = SoundCache.getSound(REMOVE_CUBE_SOUND_URL); this.COMBINE_COLORS_SOUND = SoundCache.getSound(COMBINE_COLORS_SOUND_URL); - }, - entityCollisionWithEntity: function(me, otherEntity, collision) { - + collisionWithEntity: function(me, otherEntity, collision) { var otherProperties = Entities.getEntityProperties(otherEntity, ["name", "userData"]); - var myProperties = Entities.getEntityProperties(otherEntity, ["userData"]); + var myProperties = Entities.getEntityProperties(me, ["userData"]); var myUserData = JSON.parse(myProperties.userData); var otherUserData = JSON.parse(otherProperties.userData); if (otherProperties.name === 'Hifi-ColorBusterWand') { + print('HIT ANOTHER COLOR WAND!!'); if (otherUserData.hifiColorBusterWandKey.colorLocked !== true && myUserData.hifiColorBusterWandKey.colorLocked !== true) { if (otherUserData.hifiColorBusterWandKey.originalColorName === myUserData.hifiColorBusterWandKey.originalColorName) { + print('BUT ITS THE SAME COLOR!') return; } else { + print('COMBINE COLORS!' + this.entityID); this.combineColorsWithOtherWand(otherUserData.hifiColorBusterWandKey.originalColorName, myUserData.hifiColorBusterWandKey.originalColorName); } } @@ -44,15 +65,23 @@ if (otherProperties.name === 'Hifi-ColorBusterCube') { if (otherUserData.hifiColorBusterCubeKey.originalColorName === myUserData.hifiColorBusterWandKey.currentColor) { - removeCubeOfSameColor(otherEntity); + print('HIT THE SAME COLOR CUBE'); + this.removeCubeOfSameColor(otherEntity); + } else { + print('HIT A CUBE OF A DIFFERENT COLOR'); } - } }, combineColorsWithOtherWand: function(otherColor, myColor) { - var newColor; + print('combining my :' + myColor + " with their: " + otherColor); + if ((myColor === 'violet') || (myColor === 'orange') || (myColor === 'green')) { + print('MY WAND ALREADY COMBINED'); + return; + } + + var newColor; if ((otherColor === 'red' && myColor == 'yellow') || (myColor === 'red' && otherColor === 'yellow')) { //orange newColor = 'orange'; @@ -73,19 +102,18 @@ _this.combinedColorsTimer = null; }, COMBINED_COLOR_DURATION * 1000); - setEntityCustomData(hifiColorWandKey, this.entityID, { + setEntityCustomData('hifiColorBusterWandKey', this.entityID, { owner: MyAvatar.sessionUUID, - currentColor: newColor + currentColor: newColor, originalColorName: myColor, colorLocked: false }); - _this.setCurrentColor(newColor); + this.playSoundAtCurrentPosition(false); }, setCurrentColor: function(newColor) { - var color; if (newColor === 'orange') { @@ -138,23 +166,27 @@ Entities.editEntity(this.colorIndicator, { color: color - }) + }); + + // print('SET THIS COLOR INDICATOR TO:' + newColor); }, resetToOriginalColor: function(myColor) { - setEntityCustomData(hifiColorWandKey, this.entityID, { + setEntityCustomData('hifiColorBusterWandKey', this.entityID, { owner: MyAvatar.sessionUUID, - currentColor: myColor + currentColor: myColor, originalColorName: myColor, - colorLocked: true + colorLocked: false }); this.setCurrentColor(myColor); }, removeCubeOfSameColor: function(cube) { + this.playSoundAtCurrentPosition(true); Entities.callEntityMethod(cube, 'cubeEnding'); Entities.deleteEntity(cube); + }, startNearGrab: function() { @@ -164,24 +196,31 @@ continueNearGrab: function() { this.currentProperties = Entities.getEntityProperties(this.entityID); + + var color = JSON.parse(this.currentProperties.userData).hifiColorBusterWandKey.currentColor; + + this.setCurrentColor(color); this.updateColorIndicatorLocation(); }, releaseGrab: function() { - this.deleteEntity(this.colorIndicator); + Entities.deleteEntity(this.colorIndicator); if (this.combinedColorsTimer !== null) { Script.clearTimeout(this.combinedColorsTimer); } }, - createColorIndicator: function() { + createColorIndicator: function(color) { + + var properties = { name: 'Hifi-ColorBusterIndicator', type: 'Box', dimensions: COLOR_INDICATOR_DIMENSIONS, - color: this.currentProperties.position, - position: this.currentProperties.position + position: this.currentProperties.position, + collisionsWillMove: false, + ignoreForCollisions: true } this.colorIndicator = Entities.addEntity(properties); @@ -204,15 +243,15 @@ }, - playSoundAtCurrentPosition: function(removeCubeSound) { - var position = Entities.getEntityProperties(this.entityID, "position").position; + playSoundAtCurrentPosition: function(isRemoveCubeSound) { + var position = Entities.getEntityProperties(this.entityID, "position").position; var audioProperties = { - volume: 0.25, + volume: 0.5, position: position }; - if (removeCubeSound) { + if (isRemoveCubeSound === true) { Audio.playSound(this.REMOVE_CUBE_SOUND, audioProperties); } else { Audio.playSound(this.COMBINE_COLORS_SOUND, audioProperties); diff --git a/examples/example/games/color_busters/createColorBusterCubes.js b/examples/example/games/color_busters/createColorBusterCubes.js new file mode 100644 index 0000000000..1b7aac51a5 --- /dev/null +++ b/examples/example/games/color_busters/createColorBusterCubes.js @@ -0,0 +1,130 @@ +// +// createColorBusterCubes.js +// +// Created by James B. Pollack @imgntn on 11/2/2015 +// Copyright 2015 High Fidelity, Inc. +// +// This script creates cubes that can be removed with a Color Buster wand. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +var DELETE_AT_ENDING = true; + +var CUBE_DIMENSIONS = { + x: 1, + y: 1, + z: 1 +}; + +var NUMBER_OF_CUBES_PER_SIDE = 5; + +var STARTING_CORNER_POSITION = { + x: 100, + y: 100, + z: 100 +}; +var STARTING_COLORS = [ + ['red', { + red: 255, + green: 0, + blue: 0 + }], + ['yellow', { + red: 255, + green: 255, + blue: 0 + }], + ['blue', { + red: 0, + green: 0, + blue: 255 + }], + ['orange', { + red: 255, + green: 165, + blue: 0 + }], + ['violet', { + red: 128, + green: 0, + blue: 128 + }], + ['green', { + red: 0, + green: 255, + blue: 0 + }] +]; + +function chooseStartingColor() { + var startingColor = STARTING_COLORS[Math.floor(Math.random() * STARTING_COLORS.length)]; + return startingColor; +} + +var cubes = []; + +function createColorBusterCube(row, column, vertical) { + + print('make cube at ' + row + ':' + column + ":" + vertical); + + var position = { + x: STARTING_CORNER_POSITION.x + row, + y: STARTING_CORNER_POSITION.y + vertical, + z: STARTING_CORNER_POSITION.z + column + }; + + var startingColor = chooseStartingColor(); + var colorBusterCubeProperties = { + name: 'Hifi-ColorBusterCube', + type: 'Box', + dimensions: CUBE_DIMENSIONS, + collisionsWillMove: false, + ignoreForCollisions: false, + color: startingColor[1], + position: position, + userData: JSON.stringify({ + hifiColorBusterCubeKey: { + originalColorName: startingColor[0] + }, + grabbableKey: { + grabbable: false + } + }) + }; + var cube = Entities.addEntity(colorBusterCubeProperties); + cubes.push(cube); + return cube +} + +function createBoard() { + var vertical; + var row; + var column; + for (vertical = 0; vertical < NUMBER_OF_CUBES_PER_SIDE; vertical++) { + print('vertical:' + vertical) + //create a single layer + for (row = 0; row < NUMBER_OF_CUBES_PER_SIDE; row++) { + print('row:' + row) + for (column = 0; column < NUMBER_OF_CUBES_PER_SIDE; column++) { + print('column:' + column) + createColorBusterCube(row, column, vertical) + } + } + } +} + +function deleteCubes() { + while (cubes.length > 0) { + Entities.deleteEntity(cubes.pop()); + } +} + +if (DELETE_AT_ENDING === true) { + Script.scriptEnding.connect(deleteCubes); + +} + +createBoard(); \ No newline at end of file diff --git a/examples/example/games/color_busters/createColorBusterWand.js b/examples/example/games/color_busters/createColorBusterWand.js new file mode 100644 index 0000000000..a08f529aa8 --- /dev/null +++ b/examples/example/games/color_busters/createColorBusterWand.js @@ -0,0 +1,99 @@ +// +// createColorBusterWand.js +// +// Created by James B. Pollack @imgntn on 11/2/2015 +// Copyright 2015 High Fidelity, Inc. +// +// This script creates a wand that can be used to remove color buster blocks. Touch your wand to someone else's to combine colors. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var DELETE_AT_ENDING = false; + +var COLOR_WAND_MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/color_busters/wand.fbx'; +var COLOR_WAND_COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/color_busters/wand_collision_hull.obj'; +var COLOR_WAND_SCRIPT_URL = Script.resolvePath('colorBusterWand.js'); + +var COLOR_WAND_DIMENSIONS = { + x: 0.04, + y: 0.87, + z: 0.04 +}; + +var COLOR_WAND_START_POSITION = { + x: 0, + y: 0, + z: 0 +}; + +var STARTING_COLORS = [ + ['red', { + red: 255, + green: 0, + blue: 0 + }], + ['yellow', { + red: 255, + green: 255, + blue: 0 + }], + ['blue', { + red: 0, + green: 0, + blue: 255 + }] +]; + +var center = Vec3.sum(Vec3.sum(MyAvatar.position, { + x: 0, + y: 0.5, + z: 0 +}), Vec3.multiply(0.5, Quat.getFront(Camera.getOrientation()))); + + +function chooseStartingColor() { + var startingColor = STARTING_COLORS[Math.floor(Math.random() * STARTING_COLORS.length)]; + return startingColor +} + +var wand; + +function createColorBusterWand() { + var startingColor = chooseStartingColor(); + var colorBusterWandProperties = { + name: 'Hifi-ColorBusterWand', + type: 'Model', + modelURL: COLOR_WAND_MODEL_URL, + shapeType: 'compound', + compoundShapeURL: COLOR_WAND_COLLISION_HULL_URL, + dimensions: COLOR_WAND_DIMENSIONS, + position: center, + script: COLOR_WAND_SCRIPT_URL, + collisionsWillMove: true, + userData: JSON.stringify({ + hifiColorBusterWandKey: { + owner: MyAvatar.sessionUUID, + currentColor: startingColor[0], + originalColorName: startingColor[0], + colorLocked: false + }, + grabbableKey: { + invertSolidWhileHeld: false + } + }) + }; + + wand = Entities.addEntity(colorBusterWandProperties); +} + +function deleteWand() { + Entities.deleteEntity(wand); +} + +if (DELETE_AT_ENDING === true) { + Script.scriptEnding.connect(deleteWand); +} + +createColorBusterWand(); \ No newline at end of file