smoke and fire

This commit is contained in:
ericrius1 2016-02-24 15:58:09 -08:00
parent 5520094bac
commit e245ad93d6

View file

@ -11,10 +11,13 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
(function() { (function() {
Script.include("../../libraries/utils.js");
var _this; var _this;
Fireworks = function() { Fireworks = function() {
_this = this; _this = this;
_this.launchSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/missle+launch.wav");
_this.explosionSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/fireworksExplosion.wav");
_this.timeToExplosionRange = {min: 1000, max: 2000};
}; };
Fireworks.prototype = { Fireworks.prototype = {
@ -29,24 +32,30 @@
}, },
shootFirework: function() { shootFirework: function() {
var position = Vec3.sum(_this.position, {x: 0, y: 0.5, z: 0}); var rocketPosition = Vec3.sum(_this.position, {x: 0, y: 0.1, z: 0});
Audio.playSound(_this.launchSound, {position: rocketPosition});
var MODEL_URL = "file:///C:/Users/Eric/Desktop/Rocket-2.fbx"
_this.missle = Entities.addEntity({ _this.missle = Entities.addEntity({
type: "Sphere", type: "Model",
position: position, modelURL: MODEL_URL,
position: rocketPosition,
color: {red: 200, green : 10, blue: 200}, color: {red: 200, green : 10, blue: 200},
dimensions: {x: 0.2, y: 0.4, z: 0.2}, dimensions: {x: 0.2, y: 0.4, z: 0.2},
damping: 0, damping: 0,
dynamic: true, dynamic: true,
velocity: {x: 0.0, y: 0.1, z: 0}, velocity: {x: 0.0, y: 0.1, z: 0},
gravity: {x: 0, y: 0.7, z: 0} acceleration: {x: 0, y: 1, z: 0}
}); });
var smokeTrailPosition = Vec3.sum(rocketPosition, {x: 0, y: -0.15, z: 0});
var smokeSettings = { var smokeSettings = {
type: "ParticleEffect", type: "ParticleEffect",
position: position, position: smokeTrailPosition,
lifespan: 2,
name: "Smoke Trail", name: "Smoke Trail",
maxParticles: 1000, maxParticles: 3000,
emitRate: 20, emitRate: 50,
emitSpeed: 0, emitSpeed: 0,
speedSpread: 0, speedSpread: 0,
dimensions: {x: 1000, y: 1000, z: 1000}, dimensions: {x: 1000, y: 1000, z: 1000},
@ -56,23 +65,22 @@
azimuthFinish: 3.14, azimuthFinish: 3.14,
emitAcceleration: { emitAcceleration: {
x: 0, x: 0,
y: -0.5, y: 0.1,
z: 0 z: 0
}, },
accelerationSpread: { accelerationSpread: {
x: 0.2, x: 0.1,
y: 0, y: 0,
z: 0.2 z: 0.1
}, },
radiusSpread: 0.04, radiusSpread: 0.001,
particleRadius: 0.07, particleRadius: 0.06,
radiusStart: 0.07, radiusStart: 0.06,
radiusFinish: 0.07, radiusFinish: 0.2,
alpha: 0.7, alpha: 0.1,
alphaSpread: 0, alphaSpread: 0,
alphaStart: 0, alphaStart: 0,
alphaFinish: 0, alphaFinish: 0,
additiveBlending: 0,
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
emitterShouldTrail: true, emitterShouldTrail: true,
parentID: _this.missle parentID: _this.missle
@ -80,18 +88,31 @@
_this.smoke = Entities.addEntity(smokeSettings); _this.smoke = Entities.addEntity(smokeSettings);
smokeSettings.colorStart = {red: 75, green: 193, blue: 254};
smokeSettings.color = {red: 202, green: 132, blue: 151};
smokeSettings.colorFinish = {red: 250, green: 132, blue: 21};
smokeSettings.lifespan = 0.7;
smokeSettings.emitAcceleration.y= -1;;
smokeSettings.alphaStart = 0.7;
smokeSettings.alphaFinish = 0.2;
smokeSettings.radiusFinish = 0.06;
smokeSettings.particleRadius = 0.06;
smokeSettings.emitRate = 200;
smokeSettings.emitterShouldTrail = false;
_this.fire = Entities.addEntity(smokeSettings);
Script.setTimeout(function() { // Script.setTimeout(function() {
var explodePosition = Entities.getEntityProperties(_this.missle, "position").position; // var explodePosition = Entities.getEntityProperties(_this.missle, "position").position;
Entities.deleteEntity(_this.missle); // Entities.deleteEntity(_this.missle);
Entities.deleteEntity(_this.smoke); // Entities.deleteEntity(_this.smoke);
_this.explodeFirework(explodePosition); // _this.explodeFirework(explodePosition);
}, 2500) // }, randFloat(_this.timeToExplosionRange.min, _this.timeToExplosionRange.max));
}, },
explodeFirework: function(explodePosition) { explodeFirework: function(explodePosition) {
Audio.playSound(_this.explosionSound, {position: explodePosition});
var fireworkSettings = { var fireworkSettings = {
name: "fireworks emitter", name: "fireworks emitter",
position: explodePosition, position: explodePosition,
@ -150,7 +171,7 @@
alphaSpread: 0, alphaSpread: 0,
alphaStart: 0, alphaStart: 0,
alphaFinish: 0, alphaFinish: 0,
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/spark_2.png", textures: "http://ericrius1.github.io/PlatosCave/assets/star.png",
}; };
_this.firework = Entities.addEntity(fireworkSettings); _this.firework = Entities.addEntity(fireworkSettings);
@ -166,14 +187,8 @@
_this.position = Entities.getEntityProperties(_this.entityID, "position").position; _this.position = Entities.getEntityProperties(_this.entityID, "position").position;
print("EBL RELOAD ENTITY SCRIPT!!!"); print("EBL RELOAD ENTITY SCRIPT!!!");
},
unload: function() {
Entities.deleteEntity(_this.smoke);
Entities.deleteEntity(_this.missle);
} }
}; };
// entity scripts always need to return a newly constructed object of our type // entity scripts always need to return a newly constructed object of our type