diff --git a/orfy8cilgg.js b/orfy8cilgg.js index 487142a..94f341c 100644 --- a/orfy8cilgg.js +++ b/orfy8cilgg.js @@ -459,7 +459,9 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { } var explodeParticleEngine = this.explodeParticleEngine.clone(); - explodeParticleEngine.position = mesh.position.clone(); + explodeParticleEngine.position.x = mesh.position.x; + explodeParticleEngine.position.y = mesh.position.y; + explodeParticleEngine.position.z = mesh.position.z; explodeParticleEngine.updateInstance('position'); explodeParticleEngine.enabled = true; mesh.explodeParticleEngine = explodeParticleEngine; @@ -881,23 +883,12 @@ if (this.enemySpawnTime > this.enemySpawnInterval && this.running) { } 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; - result.push(enemy); - } else { - this.kill(enemy); - } - - return result; - } - + /** + * Update enemy position and rotation + */ enemy.mesh.position.x += enemy.velocity.x * data.delta * 60; enemy.mesh.position.y += enemy.velocity.y * data.delta * 60; enemy.mesh.position.z += enemy.velocity.z * data.delta * 60; @@ -906,8 +897,10 @@ this.enemies = this.enemies.reduce( enemy.mesh.quaternion.angle += enemy.rotation.angle * data.delta; enemy.mesh.updateInstance('quaternion'); + /** + * Update its lifetime + */ enemy.lifeTime += data.delta; - if (enemy.lifeTime > enemy.life) { GameLib.Event.Emit( @@ -922,32 +915,54 @@ this.enemies = this.enemies.reduce( * We only remove the things we cloned */ this.kill(enemy); + return result; + } + + 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; + result.push(enemy); + } else { + this.kill(enemy); + } return result; + } - } else { - - if (enemy.burning) { + if (enemy.burning) { + if (!enemy.exploding) { enemy.burnTime += data.delta; - if (enemy.burnTime > enemy.burnLife) { - enemy.mesh.smokeParticleEngine.remove(); - enemy.mesh.fireParticleEngine.remove(); this.explode(enemy.mesh); - } else { - enemy.mesh.smokeParticleEngine.position = enemy.mesh.position.clone(); - enemy.mesh.smokeParticleEngine.updateInstance('position'); - enemy.mesh.fireParticleEngine.position = enemy.mesh.position.clone(); - enemy.mesh.fireParticleEngine.updateInstance('position'); } + } + if (enemy.mesh.smokeParticleEngine) { + enemy.mesh.smokeParticleEngine.position.x = enemy.mesh.position.x; + enemy.mesh.smokeParticleEngine.position.y = enemy.mesh.position.y; + enemy.mesh.smokeParticleEngine.position.z = enemy.mesh.position.z; + enemy.mesh.smokeParticleEngine.updateInstance('position'); + } + + if (enemy.mesh.fireParticleEngine) { + enemy.mesh.fireParticleEngine.position.x = enemy.mesh.position.x; + enemy.mesh.fireParticleEngine.position.y = enemy.mesh.position.y; + enemy.mesh.fireParticleEngine.position.z = enemy.mesh.position.z; + enemy.mesh.fireParticleEngine.updateInstance('position'); } result.push(enemy); return result; } + return result; + }.bind(this), [] );