(function() { Script.include("../../libraries/utils.js"); var _this; Sun = function() { _this = this; _this.weather = "sunny"; _this.rainSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/ewing/sounds/heavy-rain.wav"); _this.birdSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/ewing/sounds/birds.wav"); }; Sun.prototype = { test: function() { print("LALALA DELETE THIS HERE"); }, clickReleaseOnEntity: function() { _this.changeWeather(); }, startNearTrigger: function() { print("start near trigger"); _this.changeWeather(); }, startFarTrigger: function() { print("start far trigger"); _this.changeWeather(); }, changeWeather: function() { if (_this.weather == "sunny") { _this.addCloud(_this.position); _this.weather = "cloudy"; } else if (_this.weather == "cloudy") { _this.makeRain(_this.position); _this.weather = "rainy"; } else { _this.makeSunny(_this.position) _this.weather = "sunny"; } }, addCloud: function(sunPosition) { _this.injector.stop(); Entities.editEntity(_this.Sun, { radiusStart: 0.06, radiusFinish: 0.06, radiusSpread: 0.06, particleRadius: 0.2 // alphaStart: 0.05, // alpha: 0.05, // alphaFinish: 0.05 }); _this.cloud = Entities.addEntity({ type: "Model", position:_this.position, name: "cloud", modelURL: "https://s3-us-west-1.amazonaws.com/hifi-content/ewing/production/white-cloud.fbx", dimensions: { x: 2.056, y: 0.8, //1.164 z: 1.5 //2.2872 }, // rotation: { // x: 0, // y: 1, // z: 0, // w: 0 // }, position: { x: _this.position.x - 0.55, y: _this.position.y, z: _this.position.z + 0.1 } }); }, makeRain: function() { _this.injector = Audio.playSound(_this.rainSound, { position: _this.position, volume: 0.5, loop: true }); _this.rain = Entities.addEntity({ type: "ParticleEffect", position: { x: _this.position.x-0.5, y: _this.position.y, z: _this.position.z }, velocity: {x: 0, y:-1, z:0}, lifespan: 2, // lifetime: 1, isEmitting: true, name: "Rain", maxParticles: 3000, emitRate: 80, emitSpeed: 1, speedSpread: 0, polarStart: 0, polarFinish: 0, azimuthStart: -3.14, azimuthFinish: 3.14, emitAcceleration: { x: 0, y: 0, z: 0 }, accelerationSpread: { x: 0.01, y: 0, z: 0.01 }, // radiusSpread: 0.03, particleRadius: 0.5, radiusStart: 0.5, radiusFinish: 0.5, alpha: 0.1, alphaSpread: 0, alphaStart: 0.1, alphaFinish: 0, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", emitterShouldTrail: false, }); }, makeSunny: function(sunPosition) { Entities.editEntity(_this.Sun, { radiusStart: 0.06, radiusFinish: 0.9, radiusSpread: 0.03, particleRadius: 0.3, alphaStart: 0.7 }); _this.injector.stop(); _this.injector = Audio.playSound(_this.birdSound, { position: _this.position, volume: 0.5, loop: true }); Entities.deleteEntity(_this.rain); Entities.deleteEntity(_this.cloud); }, preload: function(entityID) { _this.entityID = entityID; _this.position = Entities.getEntityProperties(_this.entityID, "position").position; // print("UPDATED"); _this.injector = Audio.playSound(_this.birdSound, { position: _this.position, volume: 0.5, loop: true }); _this.Sun = Entities.addEntity({ type: "ParticleEffect", position: _this.position, velocity: {x: 0, y:0, z:0}, lifespan: 1, //1 lifetime: 3000, isEmitting: true, name: "Sun", maxParticles: 3000, emitRate: 80, //80 emitSpeed: 0, speedSpread: 0, polarStart: 0, polarFinish: 0, azimuthStart: -3.14, azimuthFinish: 3.14, emitAcceleration: { x: 0, y: 0, z: 0 }, accelerationSpread: { x: 0, y: 0, z: 0 }, radiusSpread: 0.03, // 0.03 particleRadius: 0.3, // 0.3 radiusStart: 0.06, // 0.06 radiusFinish: 0.9, // 0.9 alpha: 0.1, // 0.1 alphaSpread: 0, // 0 alphaStart: 0.7, // 0.7 alphaFinish: 0, // 0 textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", emitterShouldTrail: true // script: SCRIPT_URL }); } }; // entity scripts always need to return a newly constructed object of our type return new Sun(); });