diff --git a/autqzs1rvq.js b/autqzs1rvq.js index b9d41c1..742e749 100644 --- a/autqzs1rvq.js +++ b/autqzs1rvq.js @@ -14,18 +14,18 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { this.santa = this.entityLoaded.santa; this.renderer = this.entityLoaded.renderer; this.raycaster = this.entityLoaded.raycaster; - this.kanister = this.entityLoaded.kanister; + this.kanister = this.entityLoaded.kanister; this.scene = this.entityLoaded.scene; - this.leftLight = this.entityLoaded.leftLight; - this.rightLight = this.entityLoaded.rightLight; - this.throwerLight = this.entityLoaded.throwerLight; - this.smokeParticleEngine = this.entityLoaded.smokeParticleEngine; + this.leftLight = this.entityLoaded.leftLight; + this.rightLight = this.entityLoaded.rightLight; + this.throwerLight = this.entityLoaded.throwerLight; + this.smokeParticleEngine = this.entityLoaded.smokeParticleEngine; this.fireParticleEngine = this.entityLoaded.fireParticleEngine; - this.burningTreeParticleEngine = this.entityLoaded.burningTreeParticleEngine; - this.explodeParticleEngine = this.entityLoaded.explodeParticleEngine; + this.burningTreeParticleEngine = this.entityLoaded.burningTreeParticleEngine; + this.explodeParticleEngine = this.entityLoaded.explodeParticleEngine; + + this.minimumRendererRed = 0; - this.minimumRendererRed = 0; - this.toBlack = new THREE.Color(0.05, 0.05, 0.05); this.toRed = new THREE.Color(0.02, 0, 0); @@ -35,26 +35,26 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { this.parcel.instance.visible = false; this.santa.instance.visible = false; - this.treesBurning = 0; - + this.treesBurning = 0; + /** * This component is initializing - set the total time to 0 */ this.totalTime = 0; this.spawnTime = 0; - this.kanisterTime = 0; - this.kanisterLife = 16.344; - this.fuelFinished = false; + this.kanisterTime = 0; + this.kanisterLife = 16.344; + this.fuelFinished = false; + + this.level = 1; + this.spawnInterval = 5; + this.score = 0; + this.lives = 10; - this.level = 1; - this.spawnInterval = 5; - this.score = 0; - this.lives = 10; - this.enemies = []; - this.enemiesSpawned = 0; - + this.enemiesSpawned = 0; + GameLib.Event.Emit( GameLib.Event.GET_GRAPHICS_IMPLEMENTATION, null, @@ -64,31 +64,31 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { ); //this.getNextSpawnTime = function() { - /*return GameLib.Utils.GetRandomIntInclusive( - 1, - 1 - );*/ + /*return GameLib.Utils.GetRandomIntInclusive( + 1, + 1 + );*/ //} //this.nextSpawnTime = this.getNextSpawnTime(); - this.setLevelProperties = function() { - - this.prevLevel = this.level; - - this.level = Math.floor(this.enemiesSpawned / 10) + 1; - - if (this.prevLevel !== this.level) { - this.spawnInterval -= 1 / (this.level); - } - } - + this.setLevelProperties = function() { + + this.prevLevel = this.level; + + this.level = Math.floor(this.enemiesSpawned / 10) + 1; + + if (this.prevLevel !== this.level) { + this.spawnInterval -= 1 / (this.level); + } + } + this.spawnEnemy = function() { - this.enemiesSpawned++; - - this.setLevelProperties(); - + this.enemiesSpawned++; + + this.setLevelProperties(); + var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); var meshType = GameLib.Utils.GetRandomIntInclusive(1, 5); @@ -199,235 +199,235 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { enemy.life = 10; enemy.exploding = false; - enemy.burning = false; - enemy.burnLife = 3; - enemy.burnTime = 0; - enemy.explodingLife = 2; - + enemy.burning = false; + enemy.burnLife = 3; + enemy.burnTime = 0; + enemy.explodingLife = 2; + this.enemies.push(enemy); } - this.explodeMesh = function(mesh) { - - mesh.visible = false; - - mesh.updateInstance('visible'); - - var sound = GameLib.Utils.GetRandomIntInclusive(1,3); - - var name = 'Audio - Blast 1'; + this.explodeMesh = function(mesh) { - if (sound === 2) { - name = 'Audio - Blast 2'; - } + mesh.visible = false; - if (sound === 3) { - name = 'Audio - Blast 3'; - } + mesh.updateInstance('visible'); - this.blastSubscription = GameLib.Event.Subscribe( - GameLib.Event.AUDIO_ENDED, - function(data) { + var sound = GameLib.Utils.GetRandomIntInclusive(1,3); - if (data.audio.name === name) { + var name = 'Audio - Blast 1'; - if (this.blastSubscription) { + if (sound === 2) { + name = 'Audio - Blast 2'; + } - this.blastSubscription.remove(); + if (sound === 3) { + name = 'Audio - Blast 3'; + } - this.blastSubscription = null; + this.blastSubscription = GameLib.Event.Subscribe( + GameLib.Event.AUDIO_ENDED, + function(data) { - var play = GameLib.Utils.GetRandomIntInclusive(1,3); - - if (play === 1) { - - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name : 'Audio - Ho ho ho' - } - ); - } - } - } - }.bind(this) - ); + if (data.audio.name === name) { - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name : name - } - ); + if (this.blastSubscription) { + + this.blastSubscription.remove(); + + this.blastSubscription = null; + + var play = GameLib.Utils.GetRandomIntInclusive(1,3); + + if (play === 1) { + + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name : 'Audio - Ho ho ho' + } + ); + } + } + } + }.bind(this) + ); + + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name : name + } + ); + + var explodeParticleEngine = this.explodeParticleEngine.clone(); + explodeParticleEngine.position = mesh.position.clone(); + explodeParticleEngine.updateInstance('position'); + explodeParticleEngine.enabled = true; + mesh.explodeParticleEngine = explodeParticleEngine; + + }; - var explodeParticleEngine = this.explodeParticleEngine.clone(); - explodeParticleEngine.position = mesh.position.clone(); - explodeParticleEngine.updateInstance('position'); - explodeParticleEngine.enabled = true; - mesh.explodeParticleEngine = explodeParticleEngine; - - }; - this.explode = function(mesh) { - - this.enemies.map( - function(enemy) { - if (enemy.mesh === mesh && !enemy.exploding) { - console.log('exploding enemy'); - - this.score += this.level * 100; - - enemy.exploding = true; - - this.explodeMesh(mesh); - } - }.bind(this) - ); - - - } - - this.explodeKanister = function() { - this.kanisterTime = 0; - this.fuelFinished = false; - this.explodeMesh(this.kanister); - } - - this.burn = function(mesh) { - - this.enemies.map( - function(enemy) { - if (enemy.mesh === mesh && !enemy.burning) { - this.score += this.level * 10; - console.log('burning enemy ' + mesh.name); - enemy.burning = true; - var smokeParticleEngine = this.smokeParticleEngine.clone(); - smokeParticleEngine.position = mesh.position.clone(); - smokeParticleEngine.updateInstance('position'); - smokeParticleEngine.enabled = true; - mesh.smokeParticleEngine = smokeParticleEngine; - - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name : 'Audio - Burning' - } - ); - - var fireParticleEngine = this.fireParticleEngine.clone(); - fireParticleEngine.position = mesh.position.clone(); - fireParticleEngine.updateInstance('position'); - fireParticleEngine.enabled = true; - mesh.fireParticleEngine = fireParticleEngine; - } - }.bind(this) - ); - - - } - - 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 - } - ); - - /** - * Also dispose of the THREE.js objects - */ - enemy.mesh.instance.geometry.dispose(); - enemy.mesh.instance.material.dispose(); - - if (enemy.mesh.smokeParticleEngine) { - enemy.mesh.smokeParticleEngine.remove(); - enemy.mesh.smokeParticleEngine = null; - } - - if (enemy.mesh.fireParticleEngine) { - enemy.mesh.fireParticleEngine.remove(); - enemy.mesh.fireParticleEngine = null; - } - - if (enemy.mesh.explodeParticleEngine) { - enemy.mesh.explodeParticleEngine.remove(); - enemy.mesh.explodeParticleEngine = null; - } - - }; - - this.burnTree = function(mesh) { - - if (mesh.burning) { - /** - * Do nothing, this tree is burning - */ - } else { - - mesh.burning = true; - - this.treesBurning++; - - this.minimumRendererRed += 0.01; - - if (mesh.position.x < 0) { - this.leftLight.intensity += 0.07; - - if (this.leftLight.intensity >= 1) { - this.leftLight.intensity = 1; - } - - // this.leftLight.color.g -= 0.05; - // this.leftLight.color.b -= 0.05; - this.leftLight.updateInstance('intensity'); - // this.leftLight.updateInstance('color'); - } else { - this.rightLight.intensity += 0.07; + this.enemies.map( + function(enemy) { + if (enemy.mesh === mesh && !enemy.exploding) { + console.log('exploding enemy'); + + this.score += this.level * 100; + + enemy.exploding = true; + + this.explodeMesh(mesh); + } + }.bind(this) + ); + - if (this.rightLight.intensity >= 1) { - this.rightLight.intensity = 1; - } - - // this.rightLight.color.b -= 0.05; - this.rightLight.updateInstance('intensity'); - // this.rightLight.updateInstance('color'); - } - - // var smokeParticleEngine = this.smokeParticleEngine.clone(); - // smokeParticleEngine.position = mesh.position.clone(); - // smokeParticleEngine.updateInstance('position'); - // smokeParticleEngine.enabled = true; - - // mesh.smokeParticleEngine = smokeParticleEngine; - - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name : 'Audio - Burning' - } - ); - - var burningTreeParticleEngine = this.burningTreeParticleEngine.clone(); - burningTreeParticleEngine.position = mesh.position.clone(); - burningTreeParticleEngine.position.y += mesh.dimensions.y + 5; - burningTreeParticleEngine.updateInstance('position'); - burningTreeParticleEngine.enabled = true; - mesh.burningTreeParticleEngine = burningTreeParticleEngine; - } } - - this.spawnEnemy(); + + this.explodeKanister = function() { + this.kanisterTime = 0; + this.fuelFinished = false; + this.explodeMesh(this.kanister); + } + + this.burn = function(mesh) { + + this.enemies.map( + function(enemy) { + if (enemy.mesh === mesh && !enemy.burning) { + this.score += this.level * 10; + console.log('burning enemy ' + mesh.name); + enemy.burning = true; + var smokeParticleEngine = this.smokeParticleEngine.clone(); + smokeParticleEngine.position = mesh.position.clone(); + smokeParticleEngine.updateInstance('position'); + smokeParticleEngine.enabled = true; + mesh.smokeParticleEngine = smokeParticleEngine; + + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name : 'Audio - Burning' + } + ); + + var fireParticleEngine = this.fireParticleEngine.clone(); + fireParticleEngine.position = mesh.position.clone(); + fireParticleEngine.updateInstance('position'); + fireParticleEngine.enabled = true; + mesh.fireParticleEngine = fireParticleEngine; + } + }.bind(this) + ); + + + } + + 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 + } + ); + + /** + * Also dispose of the THREE.js objects + */ + enemy.mesh.instance.geometry.dispose(); + enemy.mesh.instance.material.dispose(); + + if (enemy.mesh.smokeParticleEngine) { + enemy.mesh.smokeParticleEngine.remove(); + enemy.mesh.smokeParticleEngine = null; + } + + if (enemy.mesh.fireParticleEngine) { + enemy.mesh.fireParticleEngine.remove(); + enemy.mesh.fireParticleEngine = null; + } + + if (enemy.mesh.explodeParticleEngine) { + enemy.mesh.explodeParticleEngine.remove(); + enemy.mesh.explodeParticleEngine = null; + } + + }; + + this.burnTree = function(mesh) { + + if (mesh.burning) { + /** + * Do nothing, this tree is burning + */ + } else { + + mesh.burning = true; + + this.treesBurning++; + + this.minimumRendererRed += 0.01; + + if (mesh.position.x < 0) { + this.leftLight.intensity += 0.07; + + if (this.leftLight.intensity >= 1) { + this.leftLight.intensity = 1; + } + + // this.leftLight.color.g -= 0.05; + // this.leftLight.color.b -= 0.05; + this.leftLight.updateInstance('intensity'); + // this.leftLight.updateInstance('color'); + } else { + this.rightLight.intensity += 0.07; + + if (this.rightLight.intensity >= 1) { + this.rightLight.intensity = 1; + } + + // this.rightLight.color.b -= 0.05; + this.rightLight.updateInstance('intensity'); + // this.rightLight.updateInstance('color'); + } + + // var smokeParticleEngine = this.smokeParticleEngine.clone(); + // smokeParticleEngine.position = mesh.position.clone(); + // smokeParticleEngine.updateInstance('position'); + // smokeParticleEngine.enabled = true; + + // mesh.smokeParticleEngine = smokeParticleEngine; + + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name : 'Audio - Burning' + } + ); + + var burningTreeParticleEngine = this.burningTreeParticleEngine.clone(); + burningTreeParticleEngine.position = mesh.position.clone(); + burningTreeParticleEngine.position.y += mesh.dimensions.y + 5; + burningTreeParticleEngine.updateInstance('position'); + burningTreeParticleEngine.enabled = true; + mesh.burningTreeParticleEngine = burningTreeParticleEngine; + } + } + + this.spawnEnemy(); } this.totalTime += data.delta; @@ -453,76 +453,76 @@ this.scene.meshes.map( if (this.mouseIsDown) { - this.kanisterTime += data.delta; - - if (this.kanisterTime > this.kanisterLife) { - this.fuelFinished = true; - } - - if (!this.fuelFinished) { - /** - * Light up the scene - */ - //this.fog.color.r += 0.01; - //if (this.fog.color.r > 0.5) { - // this.fog.color.r = 0.5; - //} - //this.fog.updateInstance('color'); + this.kanisterTime += data.delta; - this.renderer.clearColor.r += 0.01; - if (this.renderer.clearColor.r > 0.45) { - this.renderer.clearColor.r = 0.45; - } - this.renderer.updateInstance('clearColor'); + if (this.kanisterTime > this.kanisterLife) { + this.fuelFinished = true; + } + + if (!this.fuelFinished) { + /** + * Light up the scene + */ + //this.fog.color.r += 0.01; + //if (this.fog.color.r > 0.5) { + // this.fog.color.r = 0.5; + //} + //this.fog.updateInstance('color'); + + this.renderer.clearColor.r += 0.01; + if (this.renderer.clearColor.r > 0.45) { + this.renderer.clearColor.r = 0.45; + } + this.renderer.updateInstance('clearColor'); + + this.throwerLight.intensity += 0.05; + if (this.throwerLight.intensity > 2) { + this.throwerLight.intensity = 2; + } + this.throwerLight.updateInstance('instensity'); + } - this.throwerLight.intensity += 0.05; - if (this.throwerLight.intensity > 2) { - this.throwerLight.intensity = 2; - } - this.throwerLight.updateInstance('instensity'); - } - var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes); intersects.map( function(intersect) { var mesh = intersect.mesh; - if (mesh.name.indexOf('Kanister') !== -1) { - this.explodeKanister(); - return; - } - - if (this.fuelFinished) { - GameLib.Event.Emit(GameLib.Event.MOUSE_UP); - return; - } - + if (mesh.name.indexOf('Kanister') !== -1) { + this.explodeKanister(); + return; + } + + if (this.fuelFinished) { + GameLib.Event.Emit(GameLib.Event.MOUSE_UP); + return; + } + if ( mesh.name.indexOf('Tree - Medium') !== -1 || //tree medium mesh.name.indexOf('Hamburger') !== -1 || //burger mesh.name.indexOf('Star Cookie') !== -1 || //cookie mesh.name.indexOf('Parcel') !== -1 || //parcel - mesh.name.indexOf('Bull') !== -1|| //bull - mesh.name.indexOf('Tree - Large') !== -1 || //tree large - mesh.name.indexOf('Santa') !== -1 || //santa - mesh.name.indexOf('Tree - Small') !== -1 //tree small + mesh.name.indexOf('Bull') !== -1|| //bull + mesh.name.indexOf('Tree - Large') !== -1 || //tree large + mesh.name.indexOf('Santa') !== -1 || //santa + mesh.name.indexOf('Tree - Small') !== -1 //tree small ) { if (mesh.materials[0].name.indexOf('Trees') === -1) { mesh.instance.material.color.sub(this.toBlack); - - mesh.materials[0].color.r = mesh.instance.material.color.r; - mesh.materials[0].color.g = mesh.instance.material.color.g; - mesh.materials[0].color.b = mesh.instance.material.color.b; - - mesh.materials[0].color.instance = mesh.instance.material.color; - + + mesh.materials[0].color.r = mesh.instance.material.color.r; + mesh.materials[0].color.g = mesh.instance.material.color.g; + mesh.materials[0].color.b = mesh.instance.material.color.b; + + mesh.materials[0].color.instance = mesh.instance.material.color; + if (mesh.instance.material.color.r <= 0) { - - this.burn(mesh); - + + this.burn(mesh); + if (mesh.instance.material.emissive) { mesh.instance.material.emissive.add(this.toRed); mesh.instance.material.emissive.add(this.toRed); @@ -533,23 +533,23 @@ if (this.mouseIsDown) { } } } else { - /** - * This happens to trees - */ - if (GameLib.Utils.UndefinedOrNull(mesh.life)) { - mesh.life = 1.2; - } - - mesh.life -= 0.2; - - - // Don't do the color instance - //mesh.materials[0].color.instance = mesh.instance.material.color; - - if (mesh.life <= 0) { - this.burnTree(mesh); - - if (mesh.instance.material.emissive) { + /** + * This happens to trees + */ + if (GameLib.Utils.UndefinedOrNull(mesh.life)) { + mesh.life = 1.2; + } + + mesh.life -= 0.2; + + + // Don't do the color instance + //mesh.materials[0].color.instance = mesh.instance.material.color; + + if (mesh.life <= 0) { + this.burnTree(mesh); + + if (mesh.instance.material.emissive) { mesh.instance.material.emissive.add(this.toRed); mesh.instance.material.emissive.add(this.toRed); @@ -557,9 +557,9 @@ if (this.mouseIsDown) { // this.explode(mesh); //} } - } - - } + } + + } } }.bind(this) ); @@ -572,14 +572,14 @@ if (this.mouseIsDown) { } this.renderer.updateInstance('clearColor'); - // this.fog.color.r -= 0.01; - // if (this.fog.color.r < 0.32) { - // this.fog.color.r = 0.32; - // } - // this.fog.updateInstance('color'); - - this.throwerLight.intensity -= 0.05; - if (this.throwerLight.intensity < 0) { + // this.fog.color.r -= 0.01; + // if (this.fog.color.r < 0.32) { + // this.fog.color.r = 0.32; + // } + // this.fog.updateInstance('color'); + + this.throwerLight.intensity -= 0.05; + if (this.throwerLight.intensity < 0) { this.throwerLight.intensity = 0; } this.throwerLight.updateInstance('instensity'); @@ -592,92 +592,91 @@ if (this.spawnTime > this.spawnInterval) { if (this.kanister.explodeParticleEngine) { - if (GameLib.Utils.UndefinedOrNull(this.kanister.waiting)) { - this.kanister.waiting = true; - } else { - this.kanister.explodeParticleEngine.remove(); - this.kanister.explodeParticleEngine = null; - delete this.kanister.waiting; - } - + if (GameLib.Utils.UndefinedOrNull(this.kanister.waiting)) { + this.kanister.waiting = true; + } else { + this.kanister.explodeParticleEngine.remove(); + this.kanister.explodeParticleEngine = null; + delete this.kanister.waiting; + } + } if (this.kanisterTime > (this.kanisterLife / 2)) { - this.kanister.visible = true; - this.kanister.updateInstance('visible'); + this.kanister.visible = true; + this.kanister.updateInstance('visible'); } 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; - } - + + 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; + } + enemy.mesh.position.add(enemy.velocity); enemy.mesh.updateInstancePosition(); enemy.mesh.quaternion.angle += enemy.rotation.angle; enemy.mesh.updateInstanceRotation(); - + enemy.lifeTime += data.delta; - - if (enemy.lifeTime > enemy.life) { - - if (!enemy.burning && !enemy.exploding) { - this.lives--; - console.log('lives left: ' + this.lives); - - if (this.lives < 0) { - GameLib.Event.Emit(GameLib.Event.GAME_OVER); - } - } - - /** - * We only remove the things we cloned - */ - this.kill(enemy); - - - - return result; - + + if (enemy.lifeTime > enemy.life) { + + if (!enemy.burning && !enemy.exploding) { + this.lives--; + console.log('lives left: ' + this.lives); + + if (this.lives < 0) { + GameLib.Event.Emit(GameLib.Event.GAME_OVER); + } + } + + /** + * We only remove the things we cloned + */ + this.kill(enemy); + + + + return result; + } else { - - if (enemy.burning) { - enemy.burnTime += data.delta; - if (enemy.burnTime > enemy.burnLife) { - enemy.mesh.smokeParticleEngine.remove(); - enemy.mesh.fireParticleEngine.remove(); - enemy.lifeTime = enemy.life + 1; - enemy.burning = false; - } 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'); - } - - enemy.mesh.materials[0].opacity -= 0.005; - enemy.mesh.materials[0].updateInstance('opacity'); - - } - + + if (enemy.burning) { + enemy.burnTime += data.delta; + if (enemy.burnTime > enemy.burnLife) { + enemy.mesh.smokeParticleEngine.remove(); + enemy.mesh.fireParticleEngine.remove(); + enemy.lifeTime = enemy.life + 1; + } 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'); + } + + enemy.mesh.materials[0].opacity -= 0.005; + enemy.mesh.materials[0].updateInstance('opacity'); + + } + result.push(enemy); - return result; + return result; } - + }.bind(this), [] );