From e6db2003f98dffae4f8f20e61bad1113bdcfafc7 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Fri, 24 Nov 2017 13:15:11 +0100 Subject: [PATCH] Update: CC - Before Render - Moorcow (a2ow5l92js.js) 6028 bytes modified --- a2ow5l92js.js | 1333 +++++++++++++++++++++++++------------------------ 1 file changed, 668 insertions(+), 665 deletions(-) diff --git a/a2ow5l92js.js b/a2ow5l92js.js index 096dbaa..9688628 100644 --- a/a2ow5l92js.js +++ b/a2ow5l92js.js @@ -1,818 +1,821 @@ - if (!this.entityLoaded) { - return; - } +if (!this.entityLoaded) { + return; +} - if (GameLib.Utils.UndefinedOrNull(this.initialized)) { +if (GameLib.Utils.UndefinedOrNull(this.initialized)) { - this.initialized = true; + this.initialized = true; - GameLib.Event.Emit(GameLib.Event.STOP_ALL_AUDIO); - - this.fog = this.entityLoaded.fog; - this.bull = this.entityLoaded.bull; - this.star = this.entityLoaded.star; - this.burger = this.entityLoaded.burger; - this.parcel = this.entityLoaded.parcel; - this.santa = this.entityLoaded.santa; - this.renderer = this.entityLoaded.renderer; - this.raycaster = this.entityLoaded.raycaster; - 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.fireParticleEngine = this.entityLoaded.fireParticleEngine; - this.burningTreeParticleEngine = this.entityLoaded.burningTreeParticleEngine; - this.explodeParticleEngine = this.entityLoaded.explodeParticleEngine; + GameLib.Event.Emit(GameLib.Event.STOP_ALL_AUDIO); - this.minimumRendererRed = 0.1; + this.fog = this.entityLoaded.fog; + this.bull = this.entityLoaded.bull; + this.star = this.entityLoaded.star; + this.burger = this.entityLoaded.burger; + this.parcel = this.entityLoaded.parcel; + this.santa = this.entityLoaded.santa; + this.renderer = this.entityLoaded.renderer; + this.raycaster = this.entityLoaded.raycaster; + 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.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); + this.minimumRendererRed = 0.1; - this.bull.instance.visible = false; - this.star.instance.visible = false; - this.burger.instance.visible = false; - this.parcel.instance.visible = false; - this.santa.instance.visible = false; + this.toBlack = new THREE.Color(0.05, 0.05, 0.05); + this.toRed = new THREE.Color(0.02, 0, 0); - this.treesBurning = 0; - this.treesBurningToStart = GameLib.Utils.GetRandomIntInclusive(1, 3) + this.bull.instance.visible = false; + this.star.instance.visible = false; + this.burger.instance.visible = false; + this.parcel.instance.visible = false; + this.santa.instance.visible = false; - this.running = false; - - /** + this.treesBurning = 0; + this.treesBurningToStart = GameLib.Utils.GetRandomIntInclusive(1, 3); + + this.running = false; + + /** * 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.totalTime = 0; - this.level = 1; - this.spawnInterval = 5; - this.score = 0; - this.lives = 10; + this.kanisters = 4; + this.kanisterTime = 0; + this.kanisterLife = 16.344; + this.kanisterLeakTime = 0.001; + this.kanisterSpawnInterval = 50; - if (this.enemies instanceof Array && this.enemies.length !== 0) { - this.enemies.map( - function(enemy) { - this.kill(enemy); - }.bind(this) - ) - } - - this.scene.meshes.map( - function(mesh) { - if (mesh.burningTreeParticleEngine) { - mesh.burning = false; - mesh.life = 1.2; - mesh.burningTreeParticleEngine.remove(); - mesh.burningTreeParticleEngine = null; - } + this.fuelFinished = false; + + this.level = 1; + + this.enemySpawnInterval = 5; + this.enemySpawnTime = this.enemySpawnInterval; + + this.score = 0; + + if (this.enemies instanceof Array && this.enemies.length !== 0) { + this.enemies.map( + function(enemy) { + this.kill(enemy); }.bind(this) ) - - this.enemies = []; - - this.enemiesSpawned = 0; - - this.fog.density = 0.01; - this.fog.updateInstance('density'); - this.leftLight.intensity = 0.3; - this.leftLight.updateInstance('intensity'); - this.rightLight.intensity = 0.3; - this.rightLight.updateInstance('intensity'); - - GameLib.Event.Emit( - GameLib.Event.GAME_STARTED, - { - game : this + } + + this.scene.meshes.map( + function(mesh) { + if (mesh.burningTreeParticleEngine) { + mesh.burning = false; + mesh.life = 1.2; + mesh.burningTreeParticleEngine.remove(); + mesh.burningTreeParticleEngine = null; } - ); - - GameLib.Event.Emit( - GameLib.Event.GET_GRAPHICS_IMPLEMENTATION, - null, - function(graphics) { - this.graphics = graphics - }.bind(this) - ); + }.bind(this) + ); - this.setLevelProperties = function() { + this.enemies = []; - this.prevLevel = this.level; + this.enemiesSpawned = 0; - this.level = Math.floor(this.enemiesSpawned / 10) + 1; + this.fog.density = 0.01; + this.fog.updateInstance('density'); + this.leftLight.intensity = 0.3; + this.leftLight.updateInstance('intensity'); + this.rightLight.intensity = 0.3; + this.rightLight.updateInstance('intensity'); - if (this.prevLevel !== this.level) { - - var amount = 1 / this.level; - - if (amount < 0.1) { - amount = 0.1; - } - - this.spawnInterval -= amount; - - console.log('level : ' + this.level +', spawn interval : ' + this.spawnInterval); - - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - level : this.level, - spawnInterval : this.spawnInterval, - event : 'levelIncrease' - } - ); - } - } + GameLib.Event.Emit( + GameLib.Event.GET_GRAPHICS_IMPLEMENTATION, + null, + function(graphics) { + this.graphics = graphics + }.bind(this) + ); - this.spawnEnemy = function() { + this.setLevelProperties = function() { - this.enemiesSpawned++; - - this.setLevelProperties(); + this.prevLevel = this.level; - var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); - var meshType = GameLib.Utils.GetRandomIntInclusive(1, 5); + this.level = Math.floor(this.enemiesSpawned / 10) + 1; - var y = GameLib.Utils.GetRandomIntInclusive(2, 10); + if (this.prevLevel !== this.level) { - var speed = 1; + var amount = 1 / this.level; - var material = null; + if (amount < 0.1) { + amount = 0.1; + } - var mesh = null; - if (meshType === 1) { - mesh = this.bull.clone(); - material = this.bull.materials[0].clone(); - speed = 0.2; - } else if (meshType === 2) { - mesh = this.star.clone(); - material = this.star.materials[0].clone(); - speed = 0.3; - } else if (meshType === 3) { - mesh = this.burger.clone(); - material = this.burger.materials[0].clone(); - speed = 0.4; - } else if (meshType === 4) { - mesh = this.parcel.clone(); - material = this.parcel.materials[0].clone(); - speed = 0.5; - } else if (meshType === 5) { - mesh = this.santa.clone(); - material = this.santa.materials[0].clone(); - speed = 0.6; - } else { - console.log('unknown mesh type : ' + meshType); - } + this.enemySpawnInterval -= amount; - mesh.materials = [material]; + console.log('level : ' + this.level +', spawn interval : ' + this.enemySpawnInterval); - mesh.updateInstance(); - - mesh.instance.visible = true; - - var velocity = null; - - var axis = new GameLib.API.Vector3( - GameLib.Utils.GetRandomIntInclusive(1,10) * 0.1, - GameLib.Utils.GetRandomIntInclusive(1,10) * 0.1, - GameLib.Utils.GetRandomIntInclusive(1,10) * 0.1 - ); - - axis = axis.normalize(); - - var angle = GameLib.Utils.GetRandomIntInclusive(1,100) * 0.001; - - var position = {x : 0, y: y, z :0}; - - var rotation = { - axis : axis, - angle : angle - }; - - var enemy = { - mesh : mesh - }; - - var distance = 100; - var angledistance = distance * Math.sin(Math.PI / 4); - - var life = 2.5 / speed; - - if (enemyType === 1) { - position.x = -distance; - life += 1.5 / speed; - velocity = {x:speed,y:0,z:0}; - } - - if (enemyType === 2) { - position.x = distance; - life += 1.5 / speed; - velocity = {x:-speed,y:0,z:0}; - } - - if (enemyType === 3) { - position.x = -angledistance; - position.z = -angledistance; - velocity = {x:speed,y:0,z:speed}; - } - - if (enemyType === 4) { - position.x = angledistance; - position.z = -angledistance; - velocity = {x:-speed,y:0,z:speed}; - } - - if (enemyType === 5) { - position.x = 0; - position.z = -distance; - velocity = {x:0,y:0,z:speed}; - } - - enemy.mesh.position.x = position.x; - enemy.mesh.position.y = position.y; - enemy.mesh.position.z = position.z; - enemy.mesh.updateInstancePosition(); - - enemy.mesh.useQuaternion = true; - enemy.mesh.quaternion.axis.x = rotation.axis.x; - enemy.mesh.quaternion.axis.y = rotation.axis.y; - enemy.mesh.quaternion.axis.z = rotation.axis.z; - enemy.mesh.quaternion.angle = rotation.angle; - enemy.mesh.updateInstanceRotation(); - - enemy.velocity = velocity; - enemy.rotation = rotation; - - enemy.lifeTime = 0; - enemy.life = life; - - enemy.exploding = false; - enemy.burning = false; - enemy.burnLife = 3; - enemy.burnTime = 0; - enemy.explodingLife = 2; - enemy.meshType = meshType; - GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - enemiesSpawned : this.enemiesSpawned, - enemy : enemy, - event : 'enemySpawned' + level : this.level, + enemySpawnInterval : this.enemySpawnInterval, + event : 'levelIncrease' } ); - - this.enemies.push(enemy); - } + } + }; - this.explodeMesh = function(mesh) { + this.spawnEnemy = function() { - mesh.visible = false; + this.enemiesSpawned++; - mesh.updateInstance('visible'); + //this.setLevelProperties(); - var sound = GameLib.Utils.GetRandomIntInclusive(1,3); + var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); + var meshType = GameLib.Utils.GetRandomIntInclusive(1, 5); - var name = 'Audio - Blast 1'; + var y = GameLib.Utils.GetRandomIntInclusive(2, 10); - if (sound === 2) { - name = 'Audio - Blast 2'; - } + var speed = 1; - if (sound === 3) { - name = 'Audio - Blast 3'; - } + var material = null; - this.blastSubscription = GameLib.Event.Subscribe( - GameLib.Event.AUDIO_ENDED, - function(data) { + var mesh = null; + if (meshType === 1) { + mesh = this.bull.clone(); + material = this.bull.materials[0].clone(); + speed = 0.2; + } else if (meshType === 2) { + mesh = this.star.clone(); + material = this.star.materials[0].clone(); + speed = 0.3; + } else if (meshType === 3) { + mesh = this.burger.clone(); + material = this.burger.materials[0].clone(); + speed = 0.4; + } else if (meshType === 4) { + mesh = this.parcel.clone(); + material = this.parcel.materials[0].clone(); + speed = 0.5; + } else if (meshType === 5) { + mesh = this.santa.clone(); + material = this.santa.materials[0].clone(); + speed = 0.6; + } else { + console.log('unknown mesh type : ' + meshType); + } - if (data.audio.name === name) { + mesh.materials = [material]; - if (this.blastSubscription) { + mesh.updateInstance(); - this.blastSubscription.remove(); + mesh.instance.visible = true; - this.blastSubscription = null; + var velocity = null; - var play = GameLib.Utils.GetRandomIntInclusive(1,3); + var axis = new GameLib.API.Vector3( + GameLib.Utils.GetRandomIntInclusive(1,10) * 0.1, + GameLib.Utils.GetRandomIntInclusive(1,10) * 0.1, + GameLib.Utils.GetRandomIntInclusive(1,10) * 0.1 + ); - if (play === 1) { + axis = axis.normalize(); - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name : 'Audio - Ho ho ho' - } - ); - } - } - } - }.bind(this) - ); + var angle = GameLib.Utils.GetRandomIntInclusive(1,100) * 0.001; - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name : name - } - ); + var position = {x : 0, y: y, z :0}; - var explodeParticleEngine = this.explodeParticleEngine.clone(); - explodeParticleEngine.position = mesh.position.clone(); - explodeParticleEngine.updateInstance('position'); - explodeParticleEngine.enabled = true; - mesh.explodeParticleEngine = explodeParticleEngine; + var rotation = { + axis : axis, + angle : angle + }; - }; + var enemy = { + mesh : mesh + }; - this.explode = function(mesh) { + var distance = 100; + var angledistance = distance * Math.sin(Math.PI / 4); - this.enemies.map( - function(enemy) { - if (enemy.mesh === mesh && !enemy.exploding) { - - console.log('exploding enemy'); + var life = 2.5 / speed; - this.score += this.level * 100; + if (enemyType === 1) { + position.x = -distance; + life += 1.5 / speed; + velocity = {x:speed,y:0,z:0}; + } - enemy.exploding = true; + if (enemyType === 2) { + position.x = distance; + life += 1.5 / speed; + velocity = {x:-speed,y:0,z:0}; + } - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - score : this.score, - enemy : enemy, - event : 'enemyExploded' - } - ); - - this.explodeMesh(mesh); - } - }.bind(this) - ); + if (enemyType === 3) { + position.x = -angledistance; + position.z = -angledistance; + velocity = {x:speed,y:0,z:speed}; + } + if (enemyType === 4) { + position.x = angledistance; + position.z = -angledistance; + velocity = {x:-speed,y:0,z:speed}; + } - } + if (enemyType === 5) { + position.x = 0; + position.z = -distance; + velocity = {x:0,y:0,z:speed}; + } - this.explodeKanister = function() { - this.kanisterTime = 0; - this.fuelFinished = false; - this.explodeMesh(this.kanister); - } + enemy.mesh.position.x = position.x; + enemy.mesh.position.y = position.y; + enemy.mesh.position.z = position.z; + enemy.mesh.updateInstancePosition(); - this.burn = function(mesh) { + enemy.mesh.useQuaternion = true; + enemy.mesh.quaternion.axis.x = rotation.axis.x; + enemy.mesh.quaternion.axis.y = rotation.axis.y; + enemy.mesh.quaternion.axis.z = rotation.axis.z; + enemy.mesh.quaternion.angle = rotation.angle; + enemy.mesh.updateInstanceRotation(); - 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; - - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - score : this.score, - enemy : enemy, - event : 'enemyBurned' - } - ); - - var smokeParticleEngine = this.smokeParticleEngine.clone(); - smokeParticleEngine.position = mesh.position.clone(); - smokeParticleEngine.updateInstance('position'); - smokeParticleEngine.enabled = true; - mesh.smokeParticleEngine = smokeParticleEngine; + enemy.velocity = velocity; + enemy.rotation = rotation; - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name : 'Audio - Burning' - } - ); + enemy.lifeTime = 0; + enemy.life = life; - var fireParticleEngine = this.fireParticleEngine.clone(); - fireParticleEngine.position = mesh.position.clone(); - fireParticleEngine.updateInstance('position'); - fireParticleEngine.enabled = true; - mesh.fireParticleEngine = fireParticleEngine; - } - }.bind(this) - ); + enemy.exploding = false; + enemy.burning = false; + enemy.burnLife = 3; + enemy.burnTime = 0; + enemy.explodingLife = 2; + enemy.meshType = meshType; + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + enemiesSpawned : this.enemiesSpawned, + enemy : enemy, + event : 'enemySpawned' + } + ); - } + this.enemies.push(enemy); + }; - this.kill = function(enemy) { - /** - * We only remove the things we cloned - */ - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component : enemy.mesh.materials[0] - } - ); + this.explodeMesh = function(mesh) { - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component : enemy.mesh - } - ); + mesh.visible = false; - /** - * Also dispose of the THREE.js objects - */ - enemy.mesh.instance.geometry.dispose(); - enemy.mesh.instance.material.dispose(); + mesh.updateInstance('visible'); - if (enemy.mesh.smokeParticleEngine) { - enemy.mesh.smokeParticleEngine.remove(); - enemy.mesh.smokeParticleEngine = null; - } + var sound = GameLib.Utils.GetRandomIntInclusive(1,3); - if (enemy.mesh.fireParticleEngine) { - enemy.mesh.fireParticleEngine.remove(); - enemy.mesh.fireParticleEngine = null; - } + var name = 'Audio - Blast 1'; - if (enemy.mesh.explodeParticleEngine) { - enemy.mesh.explodeParticleEngine.remove(); - enemy.mesh.explodeParticleEngine = null; - } + if (sound === 2) { + name = 'Audio - Blast 2'; + } - }; + if (sound === 3) { + name = 'Audio - Blast 3'; + } - this.burnTree = function(mesh) { + this.blastSubscription = GameLib.Event.Subscribe( + GameLib.Event.AUDIO_ENDED, + function(data) { - if (mesh.burning) { - /** - * Do nothing, this tree is burning - */ - } else { - - mesh.burning = true; + if (data.audio.name === name) { - this.treesBurning++; + 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; + + }; + + 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; - if ( - (this.treesBurning > this.treesBurningToStart) && - !this.running - ) { - this.running = true; GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'gameRunning', - message : 'we have enough trees burning now to start - the enemy will spawn now' + score : this.score, + enemy : enemy, + event : 'enemyExploded' } ); + + 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; + + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + score : this.score, + enemy : enemy, + event : 'enemyBurned' + } + ); + + 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++; + + if ( + (this.treesBurning > this.treesBurningToStart) && + !this.running + ) { + this.running = true; GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'treeBurned', - treesBurning : this.treesBurning, - treesBurningToStart : this.treesBurningToStart + event : 'gameRunning', + message : 'we have enough trees burning now to start - the enemy will spawn now' } ); - - this.minimumRendererRed += 0.01; - - this.fog.density -= 0.00025; - if (this.fog.density < 0.0055) { - this.fog.density = 0.0055; - } - this.fog.updateInstance('density'); - - if (mesh.position.x < 0) { - this.leftLight.intensity += 0.07; - - if (this.leftLight.intensity >= 1) { - this.leftLight.intensity = 1; - } - - this.leftLight.updateInstance('intensity'); - - } else { - this.rightLight.intensity += 0.07; - - if (this.rightLight.intensity >= 1) { - this.rightLight.intensity = 1; - } - - this.rightLight.updateInstance('intensity'); - - } - - 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; - this.spawnTime += data.delta; - - this.scene.meshes.map( - function(mesh) { - if (mesh.instance.material instanceof Array) { - mesh.instance.material.map( - function(material) { - if (material.emissive) { - material.emissive.sub(this.toRed); - } - }.bind(this) - ); - } else { - if (mesh.instance.material.emissive) { - mesh.instance.material.emissive.sub(this.toRed); - } - } - }.bind(this) - ); - - if (this.mouseIsDown) { - - this.kanisterTime += data.delta; - - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - used : this.kanisterTime / this.kanisterLife, - event : 'fuelUsed', - percentage : Math.round((this.kanisterTime / this.kanisterLife) * 100) + '%' } - ); - - - if (this.kanisterTime > this.kanisterLife) { - this.fuelFinished = true; - + GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'fuelFinished' + event : 'treeBurned', + treesBurning : this.treesBurning, + treesBurningToStart : this.treesBurningToStart } ); - - } - if (!this.fuelFinished) { + this.minimumRendererRed += 0.01; - this.renderer.clearColor.r += 0.01; - if (this.renderer.clearColor.r > 0.45) { - this.renderer.clearColor.r = 0.45; - } - this.renderer.updateInstance('clearColor'); + this.fog.density -= 0.00025; + if (this.fog.density < 0.0055) { + this.fog.density = 0.0055; + } + this.fog.updateInstance('density'); - this.throwerLight.intensity += 0.05; - if (this.throwerLight.intensity > 2) { - this.throwerLight.intensity = 2; - } - this.throwerLight.updateInstance('intensity'); - } + if (mesh.position.x < 0) { + this.leftLight.intensity += 0.07; - var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes); - intersects.map( - function(intersect) { + if (this.leftLight.intensity >= 1) { + this.leftLight.intensity = 1; + } - var mesh = intersect.mesh; + this.leftLight.updateInstance('intensity'); - if (mesh.name.indexOf('Kanister') !== -1) { - this.explodeKanister(); - return; - } + } else { + this.rightLight.intensity += 0.07; - if (this.fuelFinished) { - GameLib.Event.Emit(GameLib.Event.MOUSE_UP); - return; - } + if (this.rightLight.intensity >= 1) { + this.rightLight.intensity = 1; + } - 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 - ) { + this.rightLight.updateInstance('intensity'); - if (mesh.materials[0].name.indexOf('Trees') === -1) { + } - mesh.instance.material.color.sub(this.toBlack); + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name : 'Audio - Burning' + } + ); - 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; + 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; + } + }; - mesh.materials[0].color.instance = mesh.instance.material.color; + GameLib.Event.Emit( + GameLib.Event.GAME_STARTED, + { + game : this + } + ); +} - if (mesh.instance.material.color.r <= 0) { +this.totalTime += data.delta; +this.enemySpawnTime += data.delta; - this.burn(mesh); +this.scene.meshes.map( + function(mesh) { + if (mesh.instance.material instanceof Array) { + mesh.instance.material.map( + function(material) { + if (material.emissive) { + material.emissive.sub(this.toRed); + } + }.bind(this) + ); + } else { + if (mesh.instance.material.emissive) { + mesh.instance.material.emissive.sub(this.toRed); + } + } + }.bind(this) +); - if (mesh.instance.material.emissive) { - mesh.instance.material.emissive.add(this.toRed); - mesh.instance.material.emissive.add(this.toRed); +if (this.mouseIsDown) { - if (mesh.instance.material.emissive.r >= 0.8) { - this.explode(mesh); - } - } - } - } else { - /** - * This happens to trees - */ - if (GameLib.Utils.UndefinedOrNull(mesh.life)) { - mesh.life = 1.2; - } + this.kanisterTime += data.delta; - mesh.life -= 0.2; + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + used : this.kanisterTime / this.kanisterLife, + event : 'fuelUsed', + percentage : Math.round((this.kanisterTime / this.kanisterLife) * 100) + '%' + } + ); - 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); - } - } + if (this.kanisterTime > this.kanisterLife) { + this.fuelFinished = true; - } - } - }.bind(this) - ); - - } else { - - this.renderer.clearColor.r -= 0.01; - if (this.renderer.clearColor.r < this.minimumRendererRed) { - this.renderer.clearColor.r = this.minimumRendererRed; - } - this.renderer.updateInstance('clearColor'); - - this.throwerLight.intensity -= 0.05; - if (this.throwerLight.intensity < 0) { - this.throwerLight.intensity = 0; - } - this.throwerLight.updateInstance('intensity'); - } - - if (this.spawnTime > this.spawnInterval && this.running) { - this.spawnTime = 0; - this.spawnEnemy(); - } - - 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 (this.kanisterTime > (this.kanisterLife / 2)) { - this.kanister.visible = true; - this.kanister.updateInstance('visible'); - GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'kanisterAppeared' + event : 'fuelFinished' } ); - } - this.enemies = this.enemies.reduce( - function(result, enemy) { + } - if (enemy.exploding === true) { - /** + if (!this.fuelFinished) { + + 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('intensity'); + } + + 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('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 + ) { + + 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; + + if (mesh.instance.material.color.r <= 0) { + + this.burn(mesh); + + if (mesh.instance.material.emissive) { + mesh.instance.material.emissive.add(this.toRed); + mesh.instance.material.emissive.add(this.toRed); + + if (mesh.instance.material.emissive.r >= 0.8) { + this.explode(mesh); + } + } + } + } else { + /** + * This happens to trees + */ + if (GameLib.Utils.UndefinedOrNull(mesh.life)) { + mesh.life = 1.2; + } + + mesh.life -= 0.2; + + 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); + } + } + + } + } + }.bind(this) + ); + +} else { + + this.renderer.clearColor.r -= 0.01; + if (this.renderer.clearColor.r < this.minimumRendererRed) { + this.renderer.clearColor.r = this.minimumRendererRed; + } + this.renderer.updateInstance('clearColor'); + + this.throwerLight.intensity -= 0.05; + if (this.throwerLight.intensity < 0) { + this.throwerLight.intensity = 0; + } + this.throwerLight.updateInstance('intensity'); +} + +if (this.enemySpawnTime > this.enemySpawnInterval && this.running) { + this.enemySpawnTime = 0; + this.spawnEnemy(); +} + +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 (this.kanisterTime > (this.kanisterLife / 2)) { + this.kanister.visible = true; + this.kanister.updateInstance('visible'); + + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + event : 'kanisterAppeared' + } + ); +} + +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); - } + if (GameLib.Utils.UndefinedOrNull(enemy.waiting)) { + enemy.waiting = true; + result.push(enemy); + } else { + this.kill(enemy); + } - return result; - } + return result; + } - enemy.mesh.position.add(enemy.velocity); - enemy.mesh.updateInstancePosition(); + enemy.mesh.position.add(enemy.velocity); + enemy.mesh.updateInstancePosition(); - enemy.mesh.quaternion.angle += enemy.rotation.angle; - enemy.mesh.updateInstanceRotation(); + enemy.mesh.quaternion.angle += enemy.rotation.angle; + enemy.mesh.updateInstanceRotation(); - enemy.lifeTime += data.delta; + enemy.lifeTime += data.delta; - if (enemy.lifeTime > enemy.life) { + if (enemy.lifeTime > enemy.life) { + + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + event : 'enemyLifetimeReached', + enemy : enemy + } + ); + + if (!enemy.burning && !enemy.exploding) { + + this.lives--; + + console.log('lives left: ' + this.lives); GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'enemyLifetimeReached', - enemy : enemy + livesLeft : this.lives, + event : 'lifeLost' } ); - - if (!enemy.burning && !enemy.exploding) { - - this.lives--; - - console.log('lives left: ' + this.lives); + + if (this.lives < 0) { GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - livesLeft : this.lives, - event : 'lifeLost' + event : 'gameOver', + gameData : this } ); - - if (this.lives < 0) { - - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - event : 'gameOver', - gameData : this - } - ); - - GameLib.Event.Emit(GameLib.Event.GAME_OVER); - } - } - /** + GameLib.Event.Emit(GameLib.Event.GAME_OVER); + } + } + + /** * We only remove the things we cloned */ - this.kill(enemy); + this.kill(enemy); - return result; + return result; - } else { + } 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; - } 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.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'); + enemy.mesh.materials[0].opacity -= 0.005; + enemy.mesh.materials[0].updateInstance('opacity'); - } + } - result.push(enemy); - return result; - } + result.push(enemy); + return result; + } - }.bind(this), - [] - ); + }.bind(this), + [] +); - return null; +return null; //# sourceURL=beforeRender.js \ No newline at end of file