more Particles to Entities migration

This commit is contained in:
ZappoMan 2014-10-17 10:25:52 -07:00
parent a1ecad683a
commit 6fdd489715
2 changed files with 60 additions and 59 deletions

View file

@ -95,7 +95,7 @@ var currentMoveSound = 0;
var numberOfSounds = 4;
var stepsPerSound = invaderStepsPerCycle / numberOfSounds;
// if you set this to false, sounds will come from the location of particles instead of the player's head
// if you set this to false, sounds will come from the location of entities instead of the player's head
var soundInMyHead = true;
// models...
@ -134,18 +134,17 @@ invaderModels[4] = {
function initializeMyShip() {
myShipProperties = {
type: "Model",
position: { x: middleX , y: gameAt.y, z: gameAt.z },
velocity: { x: 0, y: 0, z: 0 },
gravity: { x: 0, y: 0, z: 0 },
damping: 0,
radius: shipSize,
dimensions: { x: shipSize * 2, y: shipSize * 2, z: shipSize * 2 },
color: { red: 0, green: 255, blue: 0 },
modelURL: HIFI_PUBLIC_BUCKET + "meshes/myCannon16x16.svo",
modelScale: 450,
modelTranslation: { x: -1.3, y: -1.3, z: -1.3 },
lifetime: itemLifetimes
};
myShip = Particles.addParticle(myShipProperties);
myShip = Entities.addEntity(myShipProperties);
}
// calculate the correct invaderPosition for an column row
@ -173,16 +172,15 @@ function initializeInvaders() {
invaders[row] = new Array();
for (var column = 0; column < invadersPerRow; column++) {
invaderPosition = getInvaderPosition(row, column);
invaders[row][column] = Particles.addParticle({
invaders[row][column] = Entities.addEntity({
type: "Model",
position: invaderPosition,
velocity: { x: 0, y: 0, z: 0 },
gravity: { x: 0, y: 0, z: 0 },
damping: 0,
radius: invaderSize,
dimensions: { x: invaderSize * 2, y: invaderSize * 2, z: invaderSize * 2 },
color: { red: 255, green: 0, blue: 0 },
modelURL: invaderModels[row].modelURL,
modelScale: invaderModels[row].modelScale,
modelTranslation: invaderModels[row].modelTranslation,
lifetime: itemLifetimes
});
@ -194,10 +192,10 @@ function initializeInvaders() {
function moveInvaders() {
for (var row = 0; row < numberOfRows; row++) {
for (var column = 0; column < invadersPerRow; column++) {
props = Particles.getParticleProperties(invaders[row][column]);
props = Entities.getEntityProperties(invaders[row][column]);
if (props.isKnownID) {
invaderPosition = getInvaderPosition(row, column);
Particles.editParticle(invaders[row][column],
Entities.editEntity(invaders[row][column],
{
position: invaderPosition,
velocity: { x: 0, y: 0, z: 0 } // always reset this, incase they got collided with
@ -266,19 +264,19 @@ Script.update.connect(update);
function cleanupGame() {
print("cleaning up game...");
Particles.deleteParticle(myShip);
print("cleanupGame() ... Particles.deleteParticle(myShip)... myShip.id="+myShip.id);
Entities.deleteEntity(myShip);
print("cleanupGame() ... Entities.deleteEntity(myShip)... myShip.id="+myShip.id);
for (var row = 0; row < numberOfRows; row++) {
for (var column = 0; column < invadersPerRow; column++) {
Particles.deleteParticle(invaders[row][column]);
print("cleanupGame() ... Particles.deleteParticle(invaders[row][column])... invaders[row][column].id="
Entities.deleteEntity(invaders[row][column]);
print("cleanupGame() ... Entities.deleteEntity(invaders[row][column])... invaders[row][column].id="
+invaders[row][column].id);
}
}
// clean up our missile
if (missileFired) {
Particles.deleteParticle(myMissile);
Entities.deleteEntity(myMissile);
}
Controller.releaseKeyEvents({text: " "});
@ -293,8 +291,8 @@ function endGame() {
}
function moveShipTo(position) {
myShip = Particles.identifyParticle(myShip);
Particles.editParticle(myShip, { position: position });
myShip = Entities.identifyEntity(myShip);
Entities.editEntity(myShip, { position: position });
}
function fireMissile() {
@ -303,7 +301,7 @@ function fireMissile() {
// If we've fired a missile, then check to see if it's still alive
if (missileFired) {
var missileProperties = Particles.getParticleProperties(myMissile);
var missileProperties = Entities.getEntityProperties(myMissile);
print("missileProperties.isKnownID=" + missileProperties.isKnownID);
if (!missileProperties.isKnownID) {
@ -320,13 +318,14 @@ function fireMissile() {
y: myShipProperties.position.y + (2* shipSize),
z: myShipProperties.position.z };
myMissile = Particles.addParticle(
myMissile = Entities.addEntity(
{
type: "Sphere",
position: missilePosition,
velocity: { x: 0, y: 5, z: 0},
gravity: { x: 0, y: 0, z: 0 },
damping: 0,
radius: missileSize,
dimensions: { x: missileSize * 2, y: missileSize * 2, z: missileSize * 2 },
color: { red: 0, green: 0, blue: 255 },
lifetime: 5
});
@ -371,14 +370,14 @@ function keyPressEvent(key) {
Controller.keyPressEvent.connect(keyPressEvent);
Controller.captureKeyEvents({text: " "});
function deleteIfInvader(possibleInvaderParticle) {
function deleteIfInvader(possibleInvaderEntity) {
for (var row = 0; row < numberOfRows; row++) {
for (var column = 0; column < invadersPerRow; column++) {
invaders[row][column] = Particles.identifyParticle(invaders[row][column]);
invaders[row][column] = Entities.identifyEntity(invaders[row][column]);
if (invaders[row][column].isKnownID) {
if (invaders[row][column].id == possibleInvaderParticle.id) {
Particles.deleteParticle(possibleInvaderParticle);
Particles.deleteParticle(myMissile);
if (invaders[row][column].id == possibleInvaderEntity.id) {
Entities.deleteEntity(possibleInvaderEntity);
Entities.deleteEntity(myMissile);
// play the hit sound
var options = new AudioInjectionOptions();
@ -397,20 +396,20 @@ function deleteIfInvader(possibleInvaderParticle) {
}
}
function particleCollisionWithParticle(particleA, particleB, collision) {
print("particleCollisionWithParticle() a.id="+particleA.id + " b.id=" + particleB.id);
Vec3.print('particleCollisionWithParticle() penetration=', collision.penetration);
Vec3.print('particleCollisionWithParticle() contactPoint=', collision.contactPoint);
function entityCollisionWithEntity(entityA, entityB, collision) {
print("entityCollisionWithEntity() a.id="+entityA.id + " b.id=" + entityB.id);
Vec3.print('entityCollisionWithEntity() penetration=', collision.penetration);
Vec3.print('entityCollisionWithEntity() contactPoint=', collision.contactPoint);
if (missileFired) {
myMissile = Particles.identifyParticle(myMissile);
if (myMissile.id == particleA.id) {
deleteIfInvader(particleB);
} else if (myMissile.id == particleB.id) {
deleteIfInvader(particleA);
myMissile = Entities.identifyEntity(myMissile);
if (myMissile.id == entityA.id) {
deleteIfInvader(entityB);
} else if (myMissile.id == entityB.id) {
deleteIfInvader(entityA);
}
}
}
Particles.particleCollisionWithParticle.connect(particleCollisionWithParticle);
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
// initialize the game...

View file

@ -6,10 +6,10 @@
// Copyright 2014 High Fidelity, Inc.
//
// This is an example script that turns the hydra controllers into a toy ball catch and throw game.
// It reads the controller, watches for button presses and trigger pulls, and launches particles.
// It reads the controller, watches for button presses and trigger pulls, and launches entities.
//
// The particles it creates have a script that when they collide with Voxels, the
// particle will change it's color to match the voxel it hits.
// The entities it creates have a script that when they collide with Voxels, the
// entity will change it's color to match the voxel it hits.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -36,8 +36,8 @@ var THROWN_COLOR = { red: 128, green: 0, blue: 0 };
var leftBallAlreadyInHand = false;
var rightBallAlreadyInHand = false;
var leftHandParticle;
var rightHandParticle;
var leftHandEntity;
var rightHandEntity;
var newSound = new Sound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw");
var catchSound = new Sound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw");
@ -90,18 +90,18 @@ function checkControllerSide(whichSide) {
// If I don't currently have a ball in my hand, then try to catch closest one
if (!ballAlreadyInHand && grabButtonPressed) {
var closestParticle = Particles.findClosestParticle(palmPosition, targetRadius);
var closestEntity = Entities.findClosestEntity(palmPosition, targetRadius);
if (closestParticle.isKnownID) {
if (closestEntity.isKnownID) {
debugPrint(handMessage + " HAND- CAUGHT SOMETHING!!");
if (whichSide == LEFT_PALM) {
leftBallAlreadyInHand = true;
leftHandParticle = closestParticle;
leftHandEntity = closestEntity;
} else {
rightBallAlreadyInHand = true;
rightHandParticle = closestParticle;
rightHandEntity = closestEntity;
}
var ballPosition = getBallHoldPosition(whichSide);
var properties = { position: { x: ballPosition.x,
@ -111,7 +111,7 @@ function checkControllerSide(whichSide) {
velocity : { x: 0, y: 0, z: 0},
lifetime : 600,
inHand: true };
Particles.editParticle(closestParticle, properties);
Entities.editEntity(closestEntity, properties);
var options = new AudioInjectionOptions();
options.position = ballPosition;
@ -131,26 +131,28 @@ function checkControllerSide(whichSide) {
// If '3' is pressed, and not holding a ball, make a new one
if (grabButtonPressed && !ballAlreadyInHand) {
var ballPosition = getBallHoldPosition(whichSide);
var properties = { position: { x: ballPosition.x,
y: ballPosition.y,
z: ballPosition.z },
var properties = {
type: "Sphere",
position: { x: ballPosition.x,
y: ballPosition.y,
z: ballPosition.z },
velocity: { x: 0, y: 0, z: 0},
gravity: { x: 0, y: 0, z: 0},
inHand: true,
radius: BALL_RADIUS,
radius: { x: BALL_RADIUS * 2, y: BALL_RADIUS * 2, z: BALL_RADIUS * 2 },
damping: 0.999,
color: HELD_COLOR,
lifetime: 600 // 10 seconds - same as default, not needed but here as an example
};
newParticle = Particles.addParticle(properties);
newEntity = Entities.addEntity(properties);
if (whichSide == LEFT_PALM) {
leftBallAlreadyInHand = true;
leftHandParticle = newParticle;
leftHandEntity = newEntity;
} else {
rightBallAlreadyInHand = true;
rightHandParticle = newParticle;
rightHandEntity = newEntity;
}
// Play a new ball sound
@ -164,10 +166,10 @@ function checkControllerSide(whichSide) {
if (ballAlreadyInHand) {
if (whichSide == LEFT_PALM) {
handParticle = leftHandParticle;
handEntity = leftHandEntity;
whichTip = LEFT_TIP;
} else {
handParticle = rightHandParticle;
handEntity = rightHandEntity;
whichTip = RIGHT_TIP;
}
@ -179,7 +181,7 @@ function checkControllerSide(whichSide) {
y: ballPosition.y,
z: ballPosition.z },
};
Particles.editParticle(handParticle, properties);
Entities.editEntity(handEntity, properties);
} else {
debugPrint(">>>>> " + handMessage + "-BALL IN HAND, not grabbing, THROW!!!");
// If toy ball just released, add velocity to it!
@ -195,14 +197,14 @@ function checkControllerSide(whichSide) {
gravity: { x: 0, y: -GRAVITY_STRENGTH, z: 0},
};
Particles.editParticle(handParticle, properties);
Entities.editEntity(handEntity, properties);
if (whichSide == LEFT_PALM) {
leftBallAlreadyInHand = false;
leftHandParticle = false;
leftHandEntity = false;
} else {
rightBallAlreadyInHand = false;
rightHandParticle = false;
rightHandEntity = false;
}
var options = new AudioInjectionOptions();