transformer and tiltmaze ball

This commit is contained in:
James B. Pollack 2016-03-28 15:24:11 -07:00
parent cb1f5e3e4f
commit 42792fdd92
2 changed files with 28 additions and 16 deletions
unpublishedScripts/DomainContent/Home
dressingRoom
tiltMaze

View file

@ -146,7 +146,11 @@
delete littleVersionProps.localRotation;
delete littleVersionProps.naturalPosition;
// delete littleVersionProps.script;
littleVersionProps.gravity = {
x: 0,
y: -5,
z: 0
};
var userData = JSON.parse(littleVersionProps.userData);
var basePosition = userData["hifiHomeTransformerKey"].basePosition;
var baseRotation = userData["hifiHomeTransformerKey"].baseRotation;

View file

@ -47,7 +47,7 @@
blue: 0
};
var THROTTLE = false;
var THROTTLE = true;
var THROTTLE_RATE = 1000;
var sinceLastUpdate = 0;
@ -66,21 +66,26 @@
VICTORY_SOUND = SoundCache.getSound("http://hifi-content.s3.amazonaws.com/DomainContent/Home/tiltMaze/levelUp.wav");
Script.update.connect(this.update);
},
startNearGrab: function() {
//check to make sure a ball is in range, otherwise create one
this.testBallDistance();
},
continueNearGrab: function() {
this.testWinDistance();
this.testBallDistance();
},
continueDistantGrab: function() {
this.testBallDistance();
this.testWinDistance();
},
releaseGrab: function() {
this.testBallDistance();
},
getBallStartLocation: function() {
var mazeProps = Entities.getEntityProperties(this.entityID);
var right = Quat.getRight(mazeProps.rotation);
@ -96,6 +101,7 @@
var location = Vec3.sum(mazeProps.position, finalOffset);
return location;
},
createBall: function() {
if (this.ballLocked === true) {
return;
@ -127,6 +133,7 @@
this.ball = Entities.addEntity(properties);
},
destroyBall: function() {
var results = Entities.findEntities(MyAvatar.position, 10);
results.forEach(function(result) {
@ -137,6 +144,7 @@
}
})
},
testBallDistance: function() {
if (this.ballLocked === true) {
return;
@ -166,12 +174,12 @@
var ballSpawnerPosition = Entities.getEntityProperties(data.tiltMaze.ballSpawner, 'position').position;
var separation = Vec3.distance(ballPosition, ballSpawnerPosition);
print('ball separation: ' + separation)
if (separation > BALL_DISTANCE_THRESHOLD) {
this.destroyBall();
this.createBall();
}
},
testWinDistance: function() {
if (this.ballLocked === true) {
return;
@ -209,6 +217,7 @@
}, 1500)
}
},
playVictorySound: function() {
var position = Entities.getEntityProperties(this.entityID, "position").position;
@ -219,22 +228,21 @@
Audio.playSound(VICTORY_SOUND, audioProperties);
},
update:function(){
if (THROTTLE === true) {
sinceLastUpdate = sinceLastUpdate + deltaTime * 100;
if (sinceLastUpdate > THROTTLE_RATE) {
sinceLastUpdate = 0;
} else {
return;
update: function(deltaTime) {
if (THROTTLE === true) {
sinceLastUpdate = sinceLastUpdate + deltaTime * 100;
if (sinceLastUpdate > THROTTLE_RATE) {
sinceLastUpdate = 0;
} else {
return;
}
}
}
print('in update loop for maze, look for balls to clear')
_this.testBallDistance()
_this.testBallDistance();
},
unload:function(){
Script.update.disconnect(this.update);
unload: function() {
Script.update.disconnect(_this.update);
}
};