Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them has been replaced with a symlink. Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still be present.
109 lines
No EOL
3.9 KiB
JavaScript
109 lines
No EOL
3.9 KiB
JavaScript
//
|
|
// Carrot Client.js
|
|
//
|
|
// Team 8 Hifi Hackathon 2018
|
|
// Chang Kayla Sam Lab
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
// get distance to carrot,...if near and triggered, trigger
|
|
(function() {
|
|
var _this;
|
|
var _entityID;
|
|
|
|
var AUDIO_VOLUME_LEVEL = 0.25;
|
|
|
|
var TRIGGER_SOUND = SoundCache.getSound(Script.resolvePath("./audio/cartoon-squeak_fklEvdNd.mp3"));
|
|
var TOOFAR_TRIGGER_SOUND = SoundCache.getSound(Script.resolvePath("./audio/click-blip_fyNxFdNd.mp3"));
|
|
|
|
function Print(m) {
|
|
if (true) {
|
|
print(m)
|
|
}
|
|
}
|
|
|
|
function Carrot() {
|
|
_this = this;
|
|
}
|
|
|
|
Carrot.prototype = {
|
|
remotelyCallable: ['triggerBad'],
|
|
preload: function(entityID) {
|
|
// runs when this script is refreshed or a
|
|
// client connects to a domain where this entity is present
|
|
_this = this;
|
|
_entityID = entityID;
|
|
_this.entityID = entityID;
|
|
_this.position = Entities.getEntityProperties(_this.entityID, 'position').position;
|
|
_this.winner = JSON.parse(Entities.getEntityProperties(_this.entityID, 'userData').userData).winner;
|
|
if (_this.winner == -1) {
|
|
_this.resetPos = JSON.parse(Entities.getEntityProperties(_this.entityID, 'userData').userData).resetPos;
|
|
}
|
|
// Print(Entities.getEntityProperties(_this.entityID, 'userData').userData);
|
|
|
|
_this.sessionID = MyAvatar.sessionUUID
|
|
// Print("Carrot CLient Script loaded" + JSON.stringify(_this.position))
|
|
},
|
|
|
|
|
|
unload: function () {
|
|
// triggered when avatar leaves the domain where entity is present
|
|
// clear any intervals
|
|
// clear any listeners
|
|
// reset anything else that needs to be
|
|
},
|
|
|
|
checkTriggerOk: function() {
|
|
// we would like to check this on server side to avoid cheating...
|
|
var distance = Vec3.distance(_this.position, MyAvatar.position);
|
|
return (distance < 2.0);
|
|
},
|
|
|
|
clickDownOnEntity: function (entityID, pointerEvent) {},
|
|
clickReleaseOnEntity: function (entityID, pointerEvent) {},
|
|
holdingClickOnEntity: function (entityID, pointerEvent) {},
|
|
|
|
mouseMoveOnEntity: function (entityID, pointerEvent) {},
|
|
mousePressOnEntity: function (entityID, event) {
|
|
if (!_this.checkTriggerOk()) {
|
|
Print("Carrot Triggered pressed but TOO FAR")
|
|
_this.playSound(TOOFAR_TRIGGER_SOUND, _this.position, true)
|
|
return
|
|
} else {
|
|
Print("Carrot Triggered pressed")
|
|
Print("Sent message" + MyAvatar.sessionUUID)
|
|
_this.playSound(TRIGGER_SOUND, _this.position, false)
|
|
|
|
Entities.callEntityServerMethod(_this.entityID, 'triggerCarrot', [MyAvatar.sessionUUID]);
|
|
}
|
|
},
|
|
mouseReleaseOnEntity: function (entityID, event) {},
|
|
mouseDoublePressOffEntity: function (pointerEvent) {},
|
|
|
|
hoverEnterEntity: function (entityID, pointerEvent) {},
|
|
hoverLeaveEntity: function (entityID, pointerEvent) {},
|
|
hoverOverEntity: function (entityID, pointerEvent) {},
|
|
|
|
|
|
triggerBad: function() {
|
|
Print("I picked the BAD carrot :(");
|
|
MyAvatar.position = _this.resetPos
|
|
|
|
},
|
|
|
|
playSound: function(sound, position, local) {
|
|
if (sound.downloaded) {
|
|
Audio.playSound(sound, {
|
|
position: position,
|
|
localOnly: (local === undefined) ? false : local,
|
|
volume: AUDIO_VOLUME_LEVEL
|
|
});
|
|
}
|
|
},
|
|
|
|
};
|
|
|
|
return new Carrot();
|
|
}); |