From 0a083c070f9c00b719431da0f1d07e429b7b6587 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 30 Oct 2015 20:21:53 -0700 Subject: [PATCH 1/6] color busters cooperative game --- examples/color_busters/colorBusterWand.js | 226 ++++++++++++++++++ .../color_busters/createColorBusterCubes.js | 89 +++++++ .../color_busters/createColorBusterWand.js | 55 +++++ 3 files changed, 370 insertions(+) create mode 100644 examples/color_busters/colorBusterWand.js create mode 100644 examples/color_busters/createColorBusterCubes.js create mode 100644 examples/color_busters/createColorBusterWand.js diff --git a/examples/color_busters/colorBusterWand.js b/examples/color_busters/colorBusterWand.js new file mode 100644 index 0000000000..26948da91b --- /dev/null +++ b/examples/color_busters/colorBusterWand.js @@ -0,0 +1,226 @@ +(function() { + + //seconds that the combination lasts + var COMBINED_COLOR_DURATION = 10; + + var INDICATOR_OFFSET_UP = 0.5; + + var REMOVE_CUBE_SOUND_URL = ''; + var COMBINE_COLORS_SOUND_URL = ''; + + var _this; + + function ColorWand() { + _this = this; + }; + + ColorBusterWand.prototype = { + combinedColorsTimer: null, + + 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) { + + var otherProperties = Entities.getEntityProperties(otherEntity, ["name", "userData"]); + var myProperties = Entities.getEntityProperties(otherEntity, ["userData"]); + var myUserData = JSON.parse(myProperties.userData); + var otherUserData = JSON.parse(otherProperties.userData); + + if (otherProperties.name === 'Hifi-ColorBusterWand') { + if (otherUserData.hifiColorBusterWandKey.colorLocked !== true && myUserData.hifiColorBusterWandKey.colorLocked !== true) { + if (otherUserData.hifiColorBusterWandKey.originalColorName === myUserData.hifiColorBusterWandKey.originalColorName) { + return; + } else { + this.combineColorsWithOtherWand(otherUserData.hifiColorBusterWandKey.originalColorName, myUserData.hifiColorBusterWandKey.originalColorName); + } + } + } + + if (otherProperties.name === 'Hifi-ColorBusterCube') { + if (otherUserData.hifiColorBusterCubeKey.originalColorName === myUserData.hifiColorBusterWandKey.currentColor) { + removeCubeOfSameColor(otherEntity); + } + + } + }, + + combineColorsWithOtherWand: function(otherColor, myColor) { + var newColor; + + if ((otherColor === 'red' && myColor == 'yellow') || (myColor === 'red' && otherColor === 'yellow')) { + //orange + newColor = 'orange'; + } + + if ((otherColor === 'red' && myColor == 'blue') || (myColor === 'red' && otherColor === 'blue')) { + //violet + newColor = 'violet'; + } + + if ((otherColor === 'blue' && myColor == 'yellow') || (myColor === 'blue' && otherColor === 'yellow')) { + //green. + newColor = 'green'; + } + + _this.combinedColorsTimer = Script.setTimeout(function() { + _this.resetToOriginalColor(myColor); + _this.combinedColorsTimer = null; + }, COMBINED_COLOR_DURATION * 1000); + + setEntityCustomData(hifiColorWandKey, this.entityID, { + owner: MyAvatar.sessionUUID, + currentColor: newColor + originalColorName: myColor, + colorLocked: false + }); + + _this.setCurrentColor(newColor); + + }, + + setCurrentColor: function(newColor) { + + var color; + + if (newColor === 'orange') { + color = { + red: 255, + green: 165, + blue: 0 + }; + } + + if (newColor === 'violet') { + color = { + red: 128, + green: 0, + blue: 128 + }; + } + + if (newColor === 'green') { + color = { + red: 0, + green: 255, + blue: 0 + }; + } + + if (newColor === 'red') { + color = { + red: 255, + green: 0, + blue: 0 + }; + } + + if (newColor === 'yellow') { + color = { + red: 255, + green: 255, + blue: 0 + }; + } + + if (newColor === 'blue') { + color = { + red: 0, + green: 0, + blue: 255 + }; + } + + Entities.editEntity(this.colorIndicator, { + color: color + }) + }, + + resetToOriginalColor: function(myColor) { + setEntityCustomData(hifiColorWandKey, this.entityID, { + owner: MyAvatar.sessionUUID, + currentColor: myColor + originalColorName: myColor, + colorLocked: true + }); + + this.setCurrentColor(myColor); + }, + + removeCubeOfSameColor: function(cube) { + Entities.callEntityMethod(cube, 'cubeEnding'); + Entities.deleteEntity(cube); + }, + + startNearGrab: function() { + this.currentProperties = Entities.getEntityProperties(this.entityID); + this.createColorIndicator(); + }, + + continueNearGrab: function() { + this.currentProperties = Entities.getEntityProperties(this.entityID); + this.updateColorIndicatorLocation(); + }, + + releaseGrab: function() { + this.deleteEntity(this.colorIndicator); + if (this.combinedColorsTimer !== null) { + Script.clearTimeout(this.combinedColorsTimer); + } + + }, + + createColorIndicator: function() { + var properties = { + name: 'Hifi-ColorBusterIndicator', + type: 'Box', + dimensions: COLOR_INDICATOR_DIMENSIONS, + color: this.currentProperties.position, + position: this.currentProperties.position + } + + this.colorIndicator = Entities.addEntity(properties); + }, + + updateColorIndicatorLocation: function() { + + var position; + + var upVector = Quat.getUp(this.currentProperties.rotation); + var indicatorVector = Vec3.multiply(upVector, INDICATOR_OFFSET_UP); + position = Vec3.sum(this.currentProperties.position, indicatorVector); + + var properties = { + position: position, + rotation: this.currentProperties.rotation + } + + Entities.editEntity(this.colorIndicator, properties); + }, + + + playSoundAtCurrentPosition: function(removeCubeSound) { + var position = Entities.getEntityProperties(this.entityID, "position").position; + + var audioProperties = { + volume: 0.25, + position: position + }; + + if (removeCubeSound) { + Audio.playSound(this.REMOVE_CUBE_SOUND, audioProperties); + } else { + Audio.playSound(this.COMBINE_COLORS_SOUND, audioProperties); + } + }, + + + }; + + return new ColorBusterWand(); +}); \ No newline at end of file diff --git a/examples/color_busters/createColorBusterCubes.js b/examples/color_busters/createColorBusterCubes.js new file mode 100644 index 0000000000..ad7b8b5307 --- /dev/null +++ b/examples/color_busters/createColorBusterCubes.js @@ -0,0 +1,89 @@ +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) { + 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/createColorBusterWand.js b/examples/color_busters/createColorBusterWand.js new file mode 100644 index 0000000000..68e6ecfee5 --- /dev/null +++ b/examples/color_busters/createColorBusterWand.js @@ -0,0 +1,55 @@ +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 From 459b449a7fed46786541bebcd5691a8a3b8bbfbf Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 30 Oct 2015 20:52:19 -0700 Subject: [PATCH 2/6] rename folder --- examples/{color_busters => color_busters_game}/colorBusterWand.js | 0 .../createColorBusterCubes.js | 0 .../createColorBusterWand.js | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename examples/{color_busters => color_busters_game}/colorBusterWand.js (100%) rename examples/{color_busters => color_busters_game}/createColorBusterCubes.js (100%) rename examples/{color_busters => color_busters_game}/createColorBusterWand.js (100%) diff --git a/examples/color_busters/colorBusterWand.js b/examples/color_busters_game/colorBusterWand.js similarity index 100% rename from examples/color_busters/colorBusterWand.js rename to examples/color_busters_game/colorBusterWand.js diff --git a/examples/color_busters/createColorBusterCubes.js b/examples/color_busters_game/createColorBusterCubes.js similarity index 100% rename from examples/color_busters/createColorBusterCubes.js rename to examples/color_busters_game/createColorBusterCubes.js diff --git a/examples/color_busters/createColorBusterWand.js b/examples/color_busters_game/createColorBusterWand.js similarity index 100% rename from examples/color_busters/createColorBusterWand.js rename to examples/color_busters_game/createColorBusterWand.js From e79ebdb8aa88157fd3be5233ca7fe5a9a865661a Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sun, 1 Nov 2015 19:47:13 -0800 Subject: [PATCH 3/6] cleanup syntax --- examples/color_busters_game/createColorBusterCubes.js | 6 +++--- examples/color_busters_game/createColorBusterWand.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/color_busters_game/createColorBusterCubes.js b/examples/color_busters_game/createColorBusterCubes.js index ad7b8b5307..2bc14e5a01 100644 --- a/examples/color_busters_game/createColorBusterCubes.js +++ b/examples/color_busters_game/createColorBusterCubes.js @@ -4,7 +4,7 @@ var CUBE_DIMENSIONS = { z: 1 }; -var NUMBER_OF_CUBES_PER_SIDE: 20; +var NUMBER_OF_CUBES_PER_SIDE= 20; var STARTING_CORNER_POSITION = { x: 0, @@ -62,7 +62,7 @@ function createColorBusterCube(row, column, vertical) { x: row, y: vertical, z: column - } + }, userData: JSON.stringify({ hifiColorBusterCubeKey: { originalColorName: startingColor[0], @@ -76,7 +76,7 @@ function createColorBusterCube(row, column, vertical) { function createBoard() { var vertical; - for (vertical = 0; vertical === NUMBER_OF_CUBES_PER_SIDE) { + for (vertical = 0; vertical === NUMBER_OF_CUBES_PER_SIDE;vertical++) { var row; var column; //create a single layer diff --git a/examples/color_busters_game/createColorBusterWand.js b/examples/color_busters_game/createColorBusterWand.js index 68e6ecfee5..4af5306177 100644 --- a/examples/color_busters_game/createColorBusterWand.js +++ b/examples/color_busters_game/createColorBusterWand.js @@ -44,7 +44,7 @@ function createColorBusterWand() { userData: JSON.stringify({ hifiColorBusterWandKey: { owner: MyAvatar.sessionUUID, - currentColor: startingColor[1] + currentColor: startingColor[1], originalColorName: startingColor[0], colorLocked: false } From 15af28337b8494b6e0f8890431c8a8b0f1c545bf Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 2 Nov 2015 16:02:30 -0800 Subject: [PATCH 4/6] add color busters game for testing --- .../createColorBusterCubes.js | 89 ------------ .../createColorBusterWand.js | 55 -------- .../games/color_busters}/colorBusterWand.js | 101 +++++++++----- .../color_busters/createColorBusterCubes.js | 130 ++++++++++++++++++ .../color_busters/createColorBusterWand.js | 99 +++++++++++++ 5 files changed, 299 insertions(+), 175 deletions(-) delete mode 100644 examples/color_busters_game/createColorBusterCubes.js delete mode 100644 examples/color_busters_game/createColorBusterWand.js rename examples/{color_busters_game => example/games/color_busters}/colorBusterWand.js (69%) create mode 100644 examples/example/games/color_busters/createColorBusterCubes.js create mode 100644 examples/example/games/color_busters/createColorBusterWand.js 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 From aeac31cf6a5470f760af1536adb718e782b3d4ec Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 2 Nov 2015 16:37:24 -0800 Subject: [PATCH 5/6] dont delete cubes by default --- examples/example/games/color_busters/createColorBusterCubes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example/games/color_busters/createColorBusterCubes.js b/examples/example/games/color_busters/createColorBusterCubes.js index 1b7aac51a5..6a2942bbe9 100644 --- a/examples/example/games/color_busters/createColorBusterCubes.js +++ b/examples/example/games/color_busters/createColorBusterCubes.js @@ -11,7 +11,7 @@ // -var DELETE_AT_ENDING = true; +var DELETE_AT_ENDING = false; var CUBE_DIMENSIONS = { x: 1, From 811fd0cec7f786011dfe23bdf57634025ff21220 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 3 Nov 2015 10:42:15 -0800 Subject: [PATCH 6/6] prep for meeting --- examples/example/games/color_busters/colorBusterWand.js | 2 +- examples/example/games/color_busters/createColorBusterCubes.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example/games/color_busters/colorBusterWand.js b/examples/example/games/color_busters/colorBusterWand.js index 6080d6f345..f9d69e8414 100644 --- a/examples/example/games/color_busters/colorBusterWand.js +++ b/examples/example/games/color_busters/colorBusterWand.js @@ -247,7 +247,7 @@ var position = Entities.getEntityProperties(this.entityID, "position").position; var audioProperties = { - volume: 0.5, + volume: 0.25, position: position }; diff --git a/examples/example/games/color_busters/createColorBusterCubes.js b/examples/example/games/color_busters/createColorBusterCubes.js index 6a2942bbe9..3fdd772704 100644 --- a/examples/example/games/color_busters/createColorBusterCubes.js +++ b/examples/example/games/color_busters/createColorBusterCubes.js @@ -19,7 +19,7 @@ var CUBE_DIMENSIONS = { z: 1 }; -var NUMBER_OF_CUBES_PER_SIDE = 5; +var NUMBER_OF_CUBES_PER_SIDE = 8; var STARTING_CORNER_POSITION = { x: 100,