diff --git a/to6trvr3fj.js b/to6trvr3fj.js index aac5ee3..b3cfb54 100644 --- a/to6trvr3fj.js +++ b/to6trvr3fj.js @@ -18,6 +18,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { this.smokeParticleEngine = this.entityLoaded.smokeParticleEngine; this.fireParticleEngine = this.entityLoaded.fireParticleEngine; this.burningTreeParticleEngine = this.entityLoaded.burningTreeParticleEngine; + this.explodeParticleEngine = this.entityLoaded.explodeParticleEngine; this.toBlack = new THREE.Color(0.05, 0.05, 0.05); this.toRed = new THREE.Color(0.02, 0, 0); @@ -193,17 +194,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { name = 'Audio - Blast 3'; } - //if (this.blastSubscription) { - // GameLib.Event.Emit( - // GameLib.Event.PLAY_AUDIO, - // { - // name : 'Audio - Ho ho ho' - // } - // ); - // this.blastSubscription.remove(); - // this.blastSubscription = null; - //} - this.blastSubscription = GameLib.Event.Subscribe( GameLib.Event.AUDIO_ENDED, function(data) { @@ -234,12 +224,11 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { } ); - - // var particleEngine = this.smokeParticleEngine.clone(); - // particleEngine.position = mesh.position.clone(); - // particleEngine.updateInstance('position'); - // particleEngine.enabled = true; - // enemy.smokeParticleEngine = particleEngine; + var explodeParticleEngine = this.explodeParticleEngine.clone(); + explodeParticleEngine.position = mesh.position.clone(); + explodeParticleEngine.updateInstance('position'); + explodeParticleEngine.enabled = true; + enemy.explodeParticleEngine = explodeParticleEngine; } }.bind(this) ); @@ -279,6 +268,41 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { } + this.kill = function(enemy) { + /** + * We only remove the things we cloned + */ + GameLib.Event.Emit( + GameLib.Event.REMOVE_COMPONENT, + { + component : enemy.mesh.materials[0] + } + ); + + GameLib.Event.Emit( + GameLib.Event.REMOVE_COMPONENT, + { + component : enemy.mesh + } + ); + + if (enemy.smokeParticleEngine) { + enemy.smokeParticleEngine.remove(); + enemy.smokeParticleEngine = null; + } + + if (enemy.fireParticleEngine) { + enemy.fireParticleEngine.remove(); + enemy.fireParticleEngine = null; + } + + if (enemy.explodeParticleEngine) { + enemy.explodeParticleEngine.remove(); + enemy.explodeParticleEngine = null; + } + + }; + this.burnTree = function(mesh) { if (mesh.burning) { @@ -442,6 +466,24 @@ if (this.spawnTime > this.nextSpawnTime) { this.enemies = this.enemies.reduce( function(result, enemy) { + + if (enemy.exploding === true) { + /** + * We need to wait one render cycle for the smoke explode particle engine + * and then kill the enemy + */ + if (GameLib.Utils.UndefinedOrNull(enemy.waiting)) { + enemy.waiting = true; + enemy.mesh.visible = false; + enemy.mesh.updateInstance('visible'); + result.push(enemy); + } else { + this.kill(enemy); + } + + return result; + } + enemy.mesh.position.add(enemy.velocity); enemy.mesh.updateInstancePosition(); @@ -454,25 +496,9 @@ this.enemies = this.enemies.reduce( /** * We only remove the things we cloned */ - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component : enemy.mesh.materials[0] - } - ); - - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component : enemy.mesh - } - ); + this.kill(enemy); - if (enemy.burning) { - enemy.smokeParticleEngine.remove(); - enemy.fireParticleEngine.remove(); - enemy.burning = false; - } + return result; } else { @@ -496,8 +522,9 @@ this.enemies = this.enemies.reduce( } result.push(enemy); + return result; } - return result; + }, [] );