From af8a827c83b0fda37736cf58ee3a33b8cb7f37b0 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 10 May 2016 17:18:21 -0700 Subject: [PATCH] add fire remove plant --- .../DomainContent/Home/firePit/fire.js | 151 ++++++++++++++++++ .../DomainContent/Home/firePit/flicker.js | 51 ++++++ .../DomainContent/Home/reset.js | 17 -- 3 files changed, 202 insertions(+), 17 deletions(-) create mode 100644 unpublishedScripts/DomainContent/Home/firePit/fire.js create mode 100644 unpublishedScripts/DomainContent/Home/firePit/flicker.js diff --git a/unpublishedScripts/DomainContent/Home/firePit/fire.js b/unpublishedScripts/DomainContent/Home/firePit/fire.js new file mode 100644 index 0000000000..17cd431dd9 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/firePit/fire.js @@ -0,0 +1,151 @@ +// this script turns an entity into an exploder -- anything that collides with it will be vaporized! +// +// + +(function() { + + var _this = this; + + function Fire() { + _this = this; + } + + var RED = { + red: 255, + green: 0, + blue: 0 + }; + + var ORANGE = { + red: 255, + green: 165, + blue: 0 + }; + + var YELLOW = { + red: 255, + green: 255, + blue: 0 + }; + + var GREEN = { + red: 0, + green: 255, + blue: 0 + }; + + var BLUE = { + red: 0, + green: 0, + blue: 255 + }; + + var INDIGO = { + red: 128, + green: 0, + blue: 128 + }; + + var VIOLET = { + red: 75, + green: 0, + blue: 130 + }; + + var colors = [RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET]; + + Fire.prototype = { + preload: function(entityID) { + this.entityID = entityID; + }, + collisionWithEntity: function(myID, otherID, collisionInfo) { + var otherProps = Entities.getEntityProperties(otherID); + var data = null; + try { + data = JSON.parse(otherProps.userData) + } catch (err) { + print('ERROR GETTING USERDATA!'); + } + if (data === null || "") { + return; + } else { + if (data.hasOwnProperty('hifiHomeKey')) { + if (data.hifiHomeKey.reset === true) { + print('FLAMMABLE THING, EXPLODE IT!'); + _this.explodeWithColor(); + Entities.deleteEntity(otherID) + } + } + + } + }, + explodeWithColor: function() { + print('EXPLODE!') + var myProps = Entities.getEntityProperties(this.entityID); + var color = colors[Math.floor(Math.random() * colors.length)]; + var explosionParticleProperties = { + "color": color, + "isEmitting": 1, + "maxParticles": 1000, + "lifespan": 0.25, + "emitRate": 1, + "emitSpeed": 0.1, + "speedSpread": 1, + "emitOrientation": Quat.getUp(myProps.rotation), + "emitDimensions": { + "x": 0, + "y": 0, + "z": 0 + }, + "polarStart": 0, + "polarFinish": 0, + "azimuthStart": 0, + "azimuthFinish": 0, + "emitAcceleration": { + "x": 0, + "y": 0, + "z": 0 + }, + "accelerationSpread": { + "x": 0, + "y": 0, + "z": 0 + }, + "particleRadius": 0.829, + "radiusSpread": 0, + "radiusStart": 0.361, + "radiusFinish": 0.294, + "colorSpread": { + "red": 0, + "green": 0, + "blue": 0 + }, + "colorStart": { + "red": 255, + "green": 255, + "blue": 255 + }, + "colorFinish": { + "red": 255, + "green": 255, + "blue": 255 + }, + "alpha": 1, + "alphaSpread": 0, + "alphaStart": -0.2, + "alphaFinish": 0.5, + "emitterShouldTrail": 0, + "textures": "atp:/firepit/explode.png", + "type": "ParticleEffect", + lifetime: 1, + position:myProps.position + } + + + var explosion = Entities.addEntity(explosionParticleProperties); + print('explosion is: ' + explosion) + } + } + + return new Fire(); +}); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/firePit/flicker.js b/unpublishedScripts/DomainContent/Home/firePit/flicker.js new file mode 100644 index 0000000000..43148dabba --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/firePit/flicker.js @@ -0,0 +1,51 @@ +(function() { + + var MINIMUM_LIGHT_INTENSITY = 50.0; + var MAXIMUM_LIGHT_INTENSITY = 200.0; + var LIGHT_FALLOFF_RADIUS = 0.1; + var LIGHT_INTENSITY_RANDOMNESS = 0.1; + + function randFloat(low, high) { + return low + Math.random() * (high - low); + } + + var _this; + + function FlickeringFlame() { + _this = this; + } + + var totalTime = 0; + var spacer = 2; + FlickeringFlame.prototype = { + preload: function(entityID) { + this.entityID = entityID; + Script.update.connect(this.update); + }, + update: function(deltaTime) { + + totalTime += deltaTime; + if (totalTime > spacer) { + var howManyAvatars = AvatarList.getAvatarIdentifiers().length; + var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY))); + intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); + + Entities.editEntity(_this.entityID, { + intensity: intensity + }); + + spacer = Math.random(0, 100) * (2 / howManyAvatars); + totalTime = 0; + } else { + //just keep counting + } + }, + unload: function() { + Script.update.disconnect(this.update) + } + } + + return new FlickeringFlame + + +}); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/reset.js b/unpublishedScripts/DomainContent/Home/reset.js index 6f8dde1212..60546e5ae1 100644 --- a/unpublishedScripts/DomainContent/Home/reset.js +++ b/unpublishedScripts/DomainContent/Home/reset.js @@ -37,14 +37,10 @@ var whiteboardPath = Script.resolvePath("atp:/whiteboard/wrapper.js"); - var plantPath = Script.resolvePath("atp:/growingPlant/wrapper.js"); - var cuckooClockPath = Script.resolvePath("atp:/cuckooClock/wrapper.js"); var pingPongGunPath = Script.resolvePath("atp:/pingPongGun/wrapper.js"); - var musicBoxPath = Script.resolvePath("musicBox/wrapper.js?" + Math.random()); - var transformerPath = Script.resolvePath("atp:/dressingRoom/wrapper.js"); Script.include(utilsPath); @@ -54,10 +50,8 @@ Script.include(fishTankPath); Script.include(tiltMazePath); Script.include(whiteboardPath); - Script.include(plantPath); Script.include(cuckooClockPath); Script.include(pingPongGunPath); - // Script.include(musicBoxPath); Script.include(transformerPath); var TRANSFORMER_URL_ROBOT = 'atp:/dressingRoom/simple_robot.fbx'; @@ -213,16 +207,6 @@ z: 0 }); - var myPlant = new Plant({ - x: 1099.8785, - y: 460.3115, - z: -84.7736 - }, { - x: 0, - y: 0, - z: 0 - }); - var pingPongGun = new HomePingPongGun({ x: 1101.2123, y: 460.2328, @@ -243,7 +227,6 @@ z: 0 }); - // var musicBox = new MusicBox(); print('HOME after creating scripted entities') },