From 2b429ba2d34ed5dacec4512cbd492c6135140577 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Feb 2014 13:22:34 -0800 Subject: [PATCH 1/5] downward motion to space invaders --- examples/spaceInvadersExample.js | 63 +++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/examples/spaceInvadersExample.js b/examples/spaceInvadersExample.js index 3a13a1c52f..19b9e231e4 100644 --- a/examples/spaceInvadersExample.js +++ b/examples/spaceInvadersExample.js @@ -10,11 +10,14 @@ var iteration = 0; +var gameOver = false; + +// horizontal movement of invaders var invaderStepsPerCycle = 30; // the number of update steps it takes then invaders to move one column to the right var invaderStepOfCycle = 0; // current iteration in the cycle var invaderMoveDirection = 1; // 1 for moving to right, -1 for moving to left -var itemLifetimes = 60; +var itemLifetimes = 60 * 2; // 2 minutes var gameAt = { x: 10, y: 0, z: 10 }; var gameSize = { x: 10, y: 20, z: 1 }; var middleX = gameAt.x + (gameSize.x/2); @@ -34,6 +37,16 @@ var invadersBottomCorner = { x: gameAt.x, y: middleY , z: gameAt.z }; var rowHeight = ((gameAt.y + gameSize.y) - invadersBottomCorner.y) / numberOfRows; var columnWidth = gameSize.x / (invadersPerRow + emptyColumns); +// vertical movement of invaders +var invaderRowOffset = 0; +var stepsPerRow = 20; // number of steps before invaders really move a whole row down. + +var yPerStep = rowHeight/stepsPerRow; +var stepsToGround = (middleY - gameAt.y) / yPerStep; +var maxInvaderRowOffset=stepsToGround; + + + var missileFired = false; var myMissile; @@ -52,16 +65,19 @@ function initializeMyShip() { // calculate the correct invaderPosition for an column row function getInvaderPosition(row, column) { - var xMovePart = 0; var xBasePart = invadersBottomCorner.x + (column * columnWidth); + var xMovePart = 0; if (invaderMoveDirection > 0) { xMovePart = (invaderMoveDirection * columnWidth * (invaderStepOfCycle/invaderStepsPerCycle)); } else { xMovePart = columnWidth + (invaderMoveDirection * columnWidth * (invaderStepOfCycle/invaderStepsPerCycle)); } + + var y = invadersBottomCorner.y + (row * rowHeight) - (invaderRowOffset * rowHeight/stepsPerRow); + var invaderPosition = { x: xBasePart + xMovePart, - y: invadersBottomCorner.y + (row * rowHeight), + y: y, z: invadersBottomCorner.z }; return invaderPosition; @@ -88,7 +104,7 @@ function initializeInvaders() { } function moveInvaders() { - print("moveInvaders()..."); + //print("moveInvaders()..."); for (var row = 0; row < numberOfRows; row++) { for (var column = 0; column < invadersPerRow; column++) { props = Particles.getParticleProperties(invaders[row][column]); @@ -100,19 +116,38 @@ function moveInvaders() { } } +function displayGameOver() { + gameOver = true; + print("Game over..."); +} + function update() { - print("updating space invaders... iteration="+iteration); - iteration++; - invaderStepOfCycle++; - if (invaderStepOfCycle > invaderStepsPerCycle) { - invaderStepOfCycle = 0; - if (invaderMoveDirection > 0) { - invaderMoveDirection = -1; - } else { - invaderMoveDirection = 1; + if (!gameOver) { + //print("updating space invaders... iteration="+iteration); + iteration++; + invaderStepOfCycle++; + if (invaderStepOfCycle > invaderStepsPerCycle) { + // handle left/right movement + invaderStepOfCycle = 0; + if (invaderMoveDirection > 0) { + invaderMoveDirection = -1; + } else { + invaderMoveDirection = 1; + } + + // handle downward movement + invaderRowOffset++; // move down one row + print("invaderRowOffset="+invaderRowOffset); + + // check to see if invaders have reached "ground"... + if (invaderRowOffset > maxInvaderRowOffset) { + displayGameOver(); + return; + } + } + moveInvaders(); } - moveInvaders(); } // register the call back so it fires before each data send From 468cd0d8bbf491579d9181e75ce913fe026d0a27 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 13:21:31 -0800 Subject: [PATCH 2/5] temporary hack to work around model scale data corruption --- interface/src/ParticleTreeRenderer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/interface/src/ParticleTreeRenderer.cpp b/interface/src/ParticleTreeRenderer.cpp index d96ac2beaa..800aaa9e55 100644 --- a/interface/src/ParticleTreeRenderer.cpp +++ b/interface/src/ParticleTreeRenderer.cpp @@ -99,7 +99,11 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg // TODO: need to figure out correct scale adjust, this was arbitrarily set to make a couple models work const float MODEL_SCALE = 0.00575f; glm::vec3 scale(1.0f,1.0f,1.0f); - model->setScale(scale * MODEL_SCALE * radius * particle.getModelScale()); + + // TODO: There is some kind of a bug in packing of the particle packets which is causing modelscale to + // sometimes be garbage. We will temporarily make it always 1.0 + float modelScale = 1.0f; /// particle.getModelScale() + model->setScale(scale * MODEL_SCALE * radius * modelScale); model->simulate(0.0f); model->render(alpha); // TODO: should we allow particles to have alpha on their models? From 055dae5f78f8520f2cdd51f6bbd1458921f2e9af Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 14:04:21 -0800 Subject: [PATCH 3/5] tweak modelScale to 2.0 for better space invaders --- interface/src/ParticleTreeRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/ParticleTreeRenderer.cpp b/interface/src/ParticleTreeRenderer.cpp index 800aaa9e55..7ba714ae93 100644 --- a/interface/src/ParticleTreeRenderer.cpp +++ b/interface/src/ParticleTreeRenderer.cpp @@ -101,8 +101,8 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg glm::vec3 scale(1.0f,1.0f,1.0f); // TODO: There is some kind of a bug in packing of the particle packets which is causing modelscale to - // sometimes be garbage. We will temporarily make it always 1.0 - float modelScale = 1.0f; /// particle.getModelScale() + // sometimes be garbage. + float modelScale = 2.0f; /// particle.getModelScale() model->setScale(scale * MODEL_SCALE * radius * modelScale); model->simulate(0.0f); From 461a600d7f901aed6b7caebb92271209ff4a0b5b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 14:04:33 -0800 Subject: [PATCH 4/5] add sounds to space invaders --- examples/spaceInvadersExample.js | 54 +++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/examples/spaceInvadersExample.js b/examples/spaceInvadersExample.js index 19b9e231e4..5d3768de8b 100644 --- a/examples/spaceInvadersExample.js +++ b/examples/spaceInvadersExample.js @@ -13,7 +13,7 @@ var iteration = 0; var gameOver = false; // horizontal movement of invaders -var invaderStepsPerCycle = 30; // the number of update steps it takes then invaders to move one column to the right +var invaderStepsPerCycle = 120; // the number of update steps it takes then invaders to move one column to the right var invaderStepOfCycle = 0; // current iteration in the cycle var invaderMoveDirection = 1; // 1 for moving to right, -1 for moving to left @@ -40,16 +40,26 @@ var columnWidth = gameSize.x / (invadersPerRow + emptyColumns); // vertical movement of invaders var invaderRowOffset = 0; var stepsPerRow = 20; // number of steps before invaders really move a whole row down. - var yPerStep = rowHeight/stepsPerRow; var stepsToGround = (middleY - gameAt.y) / yPerStep; var maxInvaderRowOffset=stepsToGround; - - +// missile related items var missileFired = false; var myMissile; +// sounds +var hitSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/hit.raw"); +var shootSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/shoot.raw"); +var moveSounds = new Array(); +moveSounds[0] = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/Lo1.raw"); +moveSounds[1] = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/Lo2.raw"); +moveSounds[2] = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/Lo3.raw"); +moveSounds[3] = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/Lo4.raw"); +var currentMoveSound = 0; +var numberOfSounds = 4; +var stepsPerSound = invaderStepsPerCycle / numberOfSounds; + function initializeMyShip() { myShipProperties = { position: { x: middleX , y: gameAt.y, z: gameAt.z }, @@ -95,6 +105,7 @@ function initializeInvaders() { damping: 0, radius: shipSize, color: { red: 255, green: 0, blue: 0 }, + modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/Feisar_Ship.FBX", lifetime: itemLifetimes }); @@ -104,13 +115,16 @@ function initializeInvaders() { } function moveInvaders() { - //print("moveInvaders()..."); for (var row = 0; row < numberOfRows; row++) { for (var column = 0; column < invadersPerRow; column++) { props = Particles.getParticleProperties(invaders[row][column]); if (props.isKnownID) { invaderPosition = getInvaderPosition(row, column); - Particles.editParticle(invaders[row][column], { position: invaderPosition }); + Particles.editParticle(invaders[row][column], + { + position: invaderPosition, + velocity: { x: 0, y: 0, z: 0 } // always reset this, incase they got collided with + }); } } } @@ -125,7 +139,21 @@ function update() { if (!gameOver) { //print("updating space invaders... iteration="+iteration); iteration++; + + if (invaderStepOfCycle % stepsPerSound == 0) { + // play the move sound + var options = new AudioInjectionOptions();
 + options.position = getInvaderPosition(invadersPerRow / 2, numberOfRows / 2); + options.volume = 10.0; + Audio.playSound(moveSounds[currentMoveSound], options); + + // get ready for next move sound + currentMoveSound = (currentMoveSound+1) % numberOfSounds; + } + invaderStepOfCycle++; + + if (invaderStepOfCycle > invaderStepsPerCycle) { // handle left/right movement invaderStepOfCycle = 0; @@ -137,7 +165,7 @@ function update() { // handle downward movement invaderRowOffset++; // move down one row - print("invaderRowOffset="+invaderRowOffset); + //print("invaderRowOffset="+invaderRowOffset); // check to see if invaders have reached "ground"... if (invaderRowOffset > maxInvaderRowOffset) { @@ -217,6 +245,11 @@ function fireMissile() { lifetime: 5 }); + var options = new AudioInjectionOptions();
 + options.position = missilePosition; + options.volume = 1.0; + Audio.playSound(shootSound, options); + missileFired = true; } } @@ -254,6 +287,13 @@ function deleteIfInvader(possibleInvaderParticle) { if (invaders[row][column].id == possibleInvaderParticle.id) { Particles.deleteParticle(possibleInvaderParticle); Particles.deleteParticle(myMissile); + + // play the hit sound + var options = new AudioInjectionOptions();
 + var invaderPosition = getInvaderPosition(row, column); + options.position = invaderPosition; + options.volume = 1.0; + Audio.playSound(hitSound, options); } } } From 785e76102fc46a14737b89fc772765dc1fa5cef3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 14:22:22 -0800 Subject: [PATCH 5/5] change game at for space invaders to be close to avatar --- examples/spaceInvadersExample.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/examples/spaceInvadersExample.js b/examples/spaceInvadersExample.js index 5d3768de8b..6c8473b4d7 100644 --- a/examples/spaceInvadersExample.js +++ b/examples/spaceInvadersExample.js @@ -18,8 +18,36 @@ var invaderStepOfCycle = 0; // current iteration in the cycle var invaderMoveDirection = 1; // 1 for moving to right, -1 for moving to left var itemLifetimes = 60 * 2; // 2 minutes -var gameAt = { x: 10, y: 0, z: 10 }; + + +// position the game to be basically near the avatar running the game... var gameSize = { x: 10, y: 20, z: 1 }; +var positionFromAvatarZ = 10; + +var avatarX = MyAvatar.position.x; +var avatarY = MyAvatar.position.y; +var avatarZ = MyAvatar.position.z; +var gameAtX = avatarX; +var gameAtY = avatarY; +var gameAtZ = avatarZ; + +// move the game to be "centered" on our X +if (gameAtX > (gameSize.x/2)) { + gameAtX -= (gameSize.x/2); +} + +// move the game to be "offset slightly" on our Y +if (gameAtY > (gameSize.y/4)) { + gameAtY -= (gameSize.y/4); +} + + +// move the game to be positioned away on our Z +if (gameAtZ > positionFromAvatarZ) { + gameAtZ -= positionFromAvatarZ; +} + +var gameAt = { x: gameAtX, y: gameAtY, z: gameAtZ }; var middleX = gameAt.x + (gameSize.x/2); var middleY = gameAt.y + (gameSize.y/2);