mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-09 13:39:36 +02:00
Prevent user from setting too low of a spawn rate, rename spawnTime to spawnDuration and clean up parent object after countdown
This commit is contained in:
parent
556d0318ef
commit
f1ab013511
2 changed files with 30 additions and 21 deletions
|
@ -13,7 +13,7 @@
|
||||||
"shape": "Cube",
|
"shape": "Cube",
|
||||||
"visible": "false",
|
"visible": "false",
|
||||||
"collisionless": "true",
|
"collisionless": "true",
|
||||||
"userData": "{\"spawnRate\":1000,\"xRangeMax\":1,\"zRangeMax\":1,\"gravityCoefficient\":0.25,\"balloonLifetime\":10,\"spawnTime\":300,\"spawnMusicURL\":\"http://mpassets.highfidelity.com/8410ef73-9506-4dc7-b364-0174998a859e-v1/Audio/Blue_Skies.wav\",\"spawnMusicVolume\":0.1}"
|
"userData": "{\"spawnRate\":1000,\"xRangeMax\":1,\"zRangeMax\":1,\"gravityCoefficient\":0.25,\"balloonLifetime\":10,\"spawnDuration\":300,\"spawnMusicURL\":\"http://mpassets.highfidelity.com/8410ef73-9506-4dc7-b364-0174998a859e-v1/Audio/Blue_Skies.wav\",\"spawnMusicVolume\":0.1}"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Version": 63
|
"Version": 63
|
||||||
|
|
|
@ -28,12 +28,13 @@
|
||||||
var NUM_COLORS = 7;
|
var NUM_COLORS = 7;
|
||||||
var COUNTDOWN_SECONDS = 9;
|
var COUNTDOWN_SECONDS = 9;
|
||||||
|
|
||||||
|
var _this = this;
|
||||||
var spawnRate = 2000;
|
var spawnRate = 2000;
|
||||||
var xRangeMax = 1;
|
var xRangeMax = 1;
|
||||||
var zRangeMax = 1;
|
var zRangeMax = 1;
|
||||||
var gravityCoefficient = 0.25;
|
var gravityCoefficient = 0.25;
|
||||||
var balloonLifetime = 10;
|
var balloonLifetime = 10;
|
||||||
var spawnTime = 300;
|
var spawnDuration = 300;
|
||||||
var musicInjector;
|
var musicInjector;
|
||||||
var spawnIntervalID;
|
var spawnIntervalID;
|
||||||
var spawnMusic;
|
var spawnMusic;
|
||||||
|
@ -41,7 +42,7 @@
|
||||||
var countdownEntityID;
|
var countdownEntityID;
|
||||||
|
|
||||||
|
|
||||||
this.preload = function(pEntityID) {
|
_this.preload = function(pEntityID) {
|
||||||
var parentProperties = Entities.getEntityProperties(pEntityID, ["userData"]),
|
var parentProperties = Entities.getEntityProperties(pEntityID, ["userData"]),
|
||||||
spawnMusicURL,
|
spawnMusicURL,
|
||||||
spawnerSettings;
|
spawnerSettings;
|
||||||
|
@ -51,10 +52,10 @@
|
||||||
spawnMusicURL = spawnerSettings.spawnMusicURL ? spawnerSettings.spawnMusicURL : SPAWN_MUSIC_URL;
|
spawnMusicURL = spawnerSettings.spawnMusicURL ? spawnerSettings.spawnMusicURL : SPAWN_MUSIC_URL;
|
||||||
spawnMusic = SoundCache.getSound(spawnMusicURL);
|
spawnMusic = SoundCache.getSound(spawnMusicURL);
|
||||||
|
|
||||||
startCountdown(pEntityID);
|
_this.startCountdown(pEntityID);
|
||||||
};
|
};
|
||||||
|
|
||||||
function startCountdown(pEntityID) {
|
_this.startCountdown = function(pEntityID) {
|
||||||
var countdownSeconds = COUNTDOWN_SECONDS,
|
var countdownSeconds = COUNTDOWN_SECONDS,
|
||||||
parentProperties = Entities.getEntityProperties(pEntityID, ["position"]),
|
parentProperties = Entities.getEntityProperties(pEntityID, ["position"]),
|
||||||
countdownEntityProperties;
|
countdownEntityProperties;
|
||||||
|
@ -91,13 +92,13 @@
|
||||||
} else {
|
} else {
|
||||||
Entities.editEntity(countdownEntityID, {"text": countdownSeconds});
|
Entities.editEntity(countdownEntityID, {"text": countdownSeconds});
|
||||||
if (countdownSeconds === 0) {
|
if (countdownSeconds === 0) {
|
||||||
spawnBalloons(pEntityID);
|
_this.spawnBalloons(pEntityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
};
|
||||||
|
|
||||||
function spawnBalloons(pEntityID) {
|
_this.spawnBalloons = function(pEntityID) {
|
||||||
var parentProperties = Entities.getEntityProperties(pEntityID, ["position", "userData"]),
|
var parentProperties = Entities.getEntityProperties(pEntityID, ["position", "userData"]),
|
||||||
spawnerSettings,
|
spawnerSettings,
|
||||||
spawnMusicVolume,
|
spawnMusicVolume,
|
||||||
|
@ -110,11 +111,16 @@
|
||||||
xRangeMax = !isNaN(spawnerSettings.xRangeMax) ? spawnerSettings.xRangeMax : xRangeMax;
|
xRangeMax = !isNaN(spawnerSettings.xRangeMax) ? spawnerSettings.xRangeMax : xRangeMax;
|
||||||
zRangeMax = !isNaN(spawnerSettings.zRangeMax) ? spawnerSettings.zRangeMax : zRangeMax;
|
zRangeMax = !isNaN(spawnerSettings.zRangeMax) ? spawnerSettings.zRangeMax : zRangeMax;
|
||||||
gravityCoefficient = !isNaN(spawnerSettings.gravityCoefficient) ? spawnerSettings.gravityCoefficient : gravityCoefficient;
|
gravityCoefficient = !isNaN(spawnerSettings.gravityCoefficient) ? spawnerSettings.gravityCoefficient : gravityCoefficient;
|
||||||
spawnTime = !isNaN(spawnerSettings.spawnTime) ? spawnerSettings.spawnTime : spawnTime;
|
spawnDuration = !isNaN(spawnerSettings.spawnDuration) ? spawnerSettings.spawnDuration : spawnDuration;
|
||||||
balloonLifetime = !isNaN(spawnerSettings.balloonLifetime) ? spawnerSettings.balloonLifetime : balloonLifetime;
|
balloonLifetime = !isNaN(spawnerSettings.balloonLifetime) ? spawnerSettings.balloonLifetime : balloonLifetime;
|
||||||
spawnRate = !isNaN(spawnerSettings.spawnRate) ? spawnerSettings.spawnRate : spawnRate;
|
spawnRate = !isNaN(spawnerSettings.spawnRate) ? spawnerSettings.spawnRate : spawnRate;
|
||||||
spawnMusicVolume = !isNaN(spawnerSettings.spawnMusicVolume) ? spawnerSettings.spawnMusicVolume : 0.1;
|
spawnMusicVolume = !isNaN(spawnerSettings.spawnMusicVolume) ? spawnerSettings.spawnMusicVolume : 0.1;
|
||||||
|
|
||||||
|
if (spawnRate < 10){
|
||||||
|
spawnRate = 10;
|
||||||
|
print("The lowest balloon spawn rate allowed is 10.");
|
||||||
|
}
|
||||||
|
|
||||||
if (spawnMusic.downloaded){
|
if (spawnMusic.downloaded){
|
||||||
musicInjector = Audio.playSound(spawnMusic, {
|
musicInjector = Audio.playSound(spawnMusic, {
|
||||||
position: parentProperties.position,
|
position: parentProperties.position,
|
||||||
|
@ -183,18 +189,18 @@
|
||||||
};
|
};
|
||||||
Entities.addEntity(balloonProperties);
|
Entities.addEntity(balloonProperties);
|
||||||
|
|
||||||
//Stop spawning after spawnTime
|
//Clean up after spawnDuration
|
||||||
if (spawnCount * spawnRate / 1000 > spawnTime){
|
if (spawnCount * spawnRate / 1000 > spawnDuration){
|
||||||
Script.clearInterval(spawnIntervalID);
|
_this.cleanUp(pEntityID);
|
||||||
if (musicInjector !== undefined && musicInjector.isPlaying) {
|
|
||||||
musicInjector.stop();
|
|
||||||
musicInjector = undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, spawnRate);
|
}, spawnRate);
|
||||||
}
|
};
|
||||||
|
|
||||||
this.unload = function(){
|
_this.unload = function(){
|
||||||
|
_this.cleanUp();
|
||||||
|
};
|
||||||
|
|
||||||
|
_this.cleanUp = function(pEntityID) {
|
||||||
if (spawnIntervalID){
|
if (spawnIntervalID){
|
||||||
Script.clearInterval(spawnIntervalID);
|
Script.clearInterval(spawnIntervalID);
|
||||||
}
|
}
|
||||||
|
@ -208,6 +214,9 @@
|
||||||
musicInjector.stop();
|
musicInjector.stop();
|
||||||
musicInjector = undefined;
|
musicInjector = undefined;
|
||||||
}
|
}
|
||||||
|
if (pEntityID){
|
||||||
|
Entities.deleteEntity(pEntityID);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue