content/hifi-content/ryan/HF/balloonCage/balloon.js
2022-02-14 02:04:11 +01:00

46 lines
1.5 KiB
JavaScript

(function(){
var _this = this;
// Life value in seconds
var balloonLifeAfterDrop = 20;
var isAlive = false;
_this.preload = function(entityID){
this.entityID = entityID;
};
_this.startKillBalloon = function(entityID) {
Script.setTimeout(function(){
Entities.deleteEntity(entityID);
print("Kill balloon");
}, balloonLifeAfterDrop * 1000);
};
_this.drop = function(entityID){
var newProperties = {
gravity: {x: 0, y: -0.25, z: 0},
velocity: {x: Math.random() - Math.random(), y: Math.random() * -1, z: Math.random() - Math.random()}
};
isAlive = true;
Entities.editEntity(entityID, newProperties);
print("drop balloon");
this.startKillBalloon(this.entityID);
};
_this.clickDownOnEntity = function(entityID, event){
print("clicked on balloon");
print(entityID);
// If the balloon is in play the player can make it hop with another click
// This is a cheap way to let the user "play" with the balloon sans collision
if (isAlive){
Entities.callEntityMethod(this.entityID, "drop", entityID);
}
};
Entities.clearingEntities.connect(function(){
// Clean up any existing balloons when we shut down. They shouldn't be there when we come back.
print("cleanup!");
Entities.deleteEntity(_this.entityID);
});
});