content/hifi-content/DomainContent/production/azooz/azoozController.js
2022-02-13 22:49:05 +01:00

99 lines
2.7 KiB
JavaScript

//
// azoozController.js
//
// Created by Caitlyn Meeks on 9/3/17
// Copyright 2017 High Fidelity, Inc.
//
// An entity script for a Zone to track and display the scores from a system of pickup and trigger volume entities
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var _this = this;
var CHANNEL_PREFIX = 'io.highfidelity.azooz_server_';
var PICKUPS_CHANNEL = CHANNEL_PREFIX +"pickups";
var inZone = false;
var scoreID = 0;
var timerID = "sdfdsf";
var score = 0;
var INCREMENT_SCORE = "INCREMENT_SCORE";
var createDisplayTexts = function () {
scoreID = Overlays.addOverlay("text", {
width: 200,
height: 20,
text: "Score: 0",
alpha: 0.9,
backgroundAlpha: 1,
visible: true,
x: 80, y:40
});
timerID = Overlays.addOverlay("text", {
width: 200,
height: 20,
text: "Time: gogo5",
alpha: 0.9,
backgroundAlpha: 1,
visible: true,
x: 80, y:70
});
};
var onMessage = function(channel, message, sender) {
if (channel === PICKUPS_CHANNEL) {
if (message === INCREMENT_SCORE) {
print("AZOOZ increment score");
score++;
Overlays.editOverlay(scoreID, {text : "Score: "+score});
}
}
};
// else if (message === MESSAGE_ENTER_ZONE && !_isGameRunning) {
// _this.resetBoppo();
// } else if (message === MESSAGE_UNLOAD_FIX && _isInitialized) {
// _this.unload();
// }
_this.preload = function(entityID) {
HMD.displayModeChanged.connect(function() {
createDisplayTexts();
});
// set up a subscription to a channel
Messages.subscribe(PICKUPS_CHANNEL);
Messages.messageReceived.connect(onMessage);
};
_this.unload = function() {
Messages.unsubscribe(PICKUPS_CHANNEL);
// CLEAR HUD & VALUES
Entities.deleteEntity(scoreID);
Entities.deleteEntity(timerID);
};
_this.enterEntity = function(entityID) {
inZone = true;
createDisplayTexts();
messages.sendMessage(PICKUPS_CHANNEL, INCREMENT_SCORE);
messages.sendMessage(PICKUPS_CHANNEL, INCREMENT_SCORE);
print('AZOOZ: entered boxing glove dispenser entity');
var parentID = Entities.getEntityProperties(entityID, ['parentID']).parentID;
Messages.sendMessage(CHANNEL_PREFIX + parentID, 'enter-zone');
};
_this.leaveEntity = function(entityID) {
inZone = false;
};
_this.unload = _this.leaveEntity;
});