73 lines
No EOL
2.3 KiB
JavaScript
73 lines
No EOL
2.3 KiB
JavaScript
(function() {
|
|
|
|
print("ballScript init...")
|
|
var _this;
|
|
|
|
var soundInjector = null;
|
|
var RANGE = 5.0;
|
|
var AUDIO_RANGE = 0.5 * RANGE;
|
|
var cameraAxis = Quat.getFront(Camera.getOrientation());
|
|
var audioPosition = Vec3.sum(Camera.getPosition(), Vec3.multiply(AUDIO_RANGE, cameraAxis));
|
|
var audioOptions = { volume: 0.9, position: audioPosition };
|
|
|
|
var COLOR_TIMEOUT = 150;
|
|
|
|
function playAudio(clip) {
|
|
soundInjector = Audio.playSound(clip, audioOptions);
|
|
}
|
|
|
|
function vibrateControllers(loudness, hand) {
|
|
var strength = scale(loudness, 0, 0.35, 0, 2);
|
|
|
|
var vibrated = Controller.triggerHapticPulse(strength, 8, hand);
|
|
}
|
|
|
|
function scale(value, min1, max1, min2, max2) {
|
|
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
|
}
|
|
|
|
function getRandomInt(min, max) {
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
}
|
|
|
|
Ball = function( ) {
|
|
_this = this;
|
|
}
|
|
|
|
Ball.prototype = {
|
|
entityID: null,
|
|
preload: function(entityID) {
|
|
_this.entityID = entityID;
|
|
var SOUND_URL = "https://hifi-content.s3.amazonaws.com/lincoln/SNARE01B.wav";
|
|
_this.hitSound = SoundCache.getSound(SOUND_URL)
|
|
},
|
|
clickReleaseOnEntity: function(entityID, mouseEvent) {
|
|
|
|
var soundOptions = {
|
|
position: Entities.getEntityProperties(_this.entityID).position,
|
|
volume: 1
|
|
};
|
|
|
|
_this.injector = Audio.playSound(_this.sound, soundOptions)
|
|
|
|
|
|
if (mouseEvent.isLeftButton) {
|
|
print("clicked!")
|
|
playAudio(_this.hitSound);
|
|
Entities.editEntity(_this.entityID, {
|
|
color: { red: getRandomInt(128, 255), green: getRandomInt(128, 255), blue: getRandomInt(128, 255) }
|
|
})
|
|
}
|
|
},
|
|
collisionWithEntity: function(EntityItemID,EntityItem2ID,Collision) {
|
|
// print(JSON.stringify(Collision))
|
|
playAudio(_this.hitSound);
|
|
Entities.editEntity(_this.entityID, {
|
|
color: { red: getRandomInt(128, 255), green: getRandomInt(128, 255), blue: getRandomInt(128, 255) }
|
|
})
|
|
},
|
|
}
|
|
|
|
return new Ball();
|
|
|
|
}) |