From 84612acddb3ff509fd00c1f959ae3045a3795075 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Wed, 7 Mar 2018 05:47:10 +0100 Subject: [PATCH] Update: CC - Before Render - Moorcow (qemp4een6t.js) 8213 bytes modified --- qemp4een6t.js | 1584 ++++++++++++++++++++++++------------------------- 1 file changed, 787 insertions(+), 797 deletions(-) diff --git a/qemp4een6t.js b/qemp4een6t.js index 3a001f9..ebea906 100644 --- a/qemp4een6t.js +++ b/qemp4een6t.js @@ -1,946 +1,936 @@ + if (!this.entityLoaded) { + return; + } + + if (GameLib.Utils.UndefinedOrNull(this.initialized)) { + + this.initialized = true; + + GameLib.Event.Emit(GameLib.Event.STOP_ALL_AUDIO); + + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name: 'Audio - Xmas' + } + ); + + if (this.blastSubscription) { + this.blastSubscription.remove(); + } + + this.blastSubscription = GameLib.Event.Subscribe( + GameLib.Event.AUDIO_ENDED, + function (data) { + if (data.audio.name.indexOf('Blast') !== -1) { + var play = GameLib.Utils.GetRandomIntInclusive(1, 5); + if (play === 1) { + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name: 'Audio - Ho ho ho' + } + ); + } + } + }.bind(this) + ); + + this.bull = this.entityLoaded.bull; + this.star = this.entityLoaded.star; + this.santa = this.entityLoaded.santa; + this.scene = this.entityLoaded.scene; + this.camera = this.entityLoaded.camera; + this.burger = this.entityLoaded.burger; + this.parcel = this.entityLoaded.parcel; + this.meshes = this.entityLoaded.meshes; + this.renderer = this.entityLoaded.renderer; + this.raycaster = this.entityLoaded.raycaster; + this.kanister = this.entityLoaded.kanister; + this.leftLight = this.entityLoaded.leftLight; + this.rightLight = this.entityLoaded.rightLight; + this.scoreCanvas = this.entityLoaded.scoreCanvas; + this.scoreTexture = this.entityLoaded.scoreTexture; + this.scoreMesh = this.entityLoaded.scoreMesh; + this.throwerLight = this.entityLoaded.throwerLight; + this.fireParticleEngine = this.entityLoaded.fireParticleEngine; + this.smokeParticleEngine = this.entityLoaded.smokeParticleEngine; + this.explodeParticleEngine = this.entityLoaded.explodeParticleEngine; + this.burningTreeParticleEngine = this.entityLoaded.burningTreeParticleEngine; + + this.minimumRendererRed = 0.1; + + this.toBlack = new THREE.Color( + data.delta * 3, + data.delta * 3, + data.delta * 3 + ); + + this.toRed = new THREE.Color( + data.delta * 1.2, + 0, + 0 + ); + + this.treesBurning = 0; + this.treesBurningToStart = GameLib.Utils.GetRandomIntInclusive(1, 3); + + this.running = false; + + this.totalTime = 0; + + this.kanisters = 2; + this.kanisterTime = 0; + this.kanisterLife = 16.344; + this.kanisterLeakTime = 0.1; + this.kanisterSpawnScore = 500; + + this.enemiesBurned = 0; + this.enemiesExploded = 0; + + this.setNextKanisterSpawnScore = function () { + + if (this.score > 500) { + this.kanisterSpawnScore = 1000; + } + + if (this.score > 1000) { + this.kanisterSpawnScore = 1500; + } + + if (this.score > 1500) { + this.kanisterSpawnScore = 2500; + } + + if (this.score > 2500) { + this.kanisterSpawnScore = 5000; + } + + if (this.score > 5000) { + var dice = GameLib.Utils.GetRandomIntInclusive(1, 10); + + /** + * Max average spawn = 5.41 + * @type {number} + */ + dice += 6.41; + + /** + * 53 is one more than average score, in total - should be against your odds to win. + */ + this.kanisterSpawnScore = this.score + (dice * 53 * this.level); + } + + console.log('next kanister spawn score: ' + this.kanisterSpawnScore); + + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + event: 'nextKanisterSpawnScoreUpdate', + kanisterSpawnScore: this.kanisterSpawnScore + } + ); + }; + + 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.scene.meshes.map( + function (mesh) { + if (mesh.burningTreeParticleEngine) { + mesh.burning = false; + mesh.burnLife = 1; + mesh.burningTreeParticleEngine.enabled = false; + } + }.bind(this) + ); -if (!this.entityLoaded) { - return; -} - -if (GameLib.Utils.UndefinedOrNull(this.initialized)) { - - this.initialized = true; - - GameLib.Event.Emit(GameLib.Event.STOP_ALL_AUDIO); - - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name: 'Audio - Xmas' - } - ); - - if (this.blastSubscription) { - this.blastSubscription.remove(); - } - - this.blastSubscription = GameLib.Event.Subscribe( - GameLib.Event.AUDIO_ENDED, - function (data) { - if (data.audio.name.indexOf('Blast') !== -1) { - var play = GameLib.Utils.GetRandomIntInclusive(1, 5); - if (play === 1) { - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name: 'Audio - Ho ho ho' - } - ); - } - } - }.bind(this) - ); - - this.fog = this.entityLoaded.fog; - this.bull = this.entityLoaded.bull; - this.star = this.entityLoaded.star; - this.santa = this.entityLoaded.santa; - this.scene = this.entityLoaded.scene; - this.camera = this.entityLoaded.camera; - this.burger = this.entityLoaded.burger; - this.parcel = this.entityLoaded.parcel; - this.meshes = this.entityLoaded.meshes; - this.renderer = this.entityLoaded.renderer; - this.raycaster = this.entityLoaded.raycaster; - this.kanister = this.entityLoaded.kanister; - this.leftLight = this.entityLoaded.leftLight; - this.rightLight = this.entityLoaded.rightLight; - this.scoreCanvas = this.entityLoaded.scoreCanvas; - this.scoreTexture = this.entityLoaded.scoreTexture; - this.scoreMesh = this.entityLoaded.scoreMesh; - this.throwerLight = this.entityLoaded.throwerLight; - this.fireParticleEngine = this.entityLoaded.fireParticleEngine; - this.smokeParticleEngine = this.entityLoaded.smokeParticleEngine; - this.explodeParticleEngine = this.entityLoaded.explodeParticleEngine; - this.burningTreeParticleEngine = this.entityLoaded.burningTreeParticleEngine; - - this.minimumRendererRed = 0.1; - - this.toBlack = new THREE.Color( - data.delta * 3, - data.delta * 3, - data.delta * 3 - ); - - this.toRed = new THREE.Color( - data.delta * 1.2, - 0, - 0 - ); - - this.treesBurning = 0; - this.treesBurningToStart = GameLib.Utils.GetRandomIntInclusive(1, 3); - - this.running = false; - - this.totalTime = 0; - - this.kanisters = 2; - this.kanisterTime = 0; - this.kanisterLife = 16.344; - this.kanisterLeakTime = 0.1; - this.kanisterSpawnScore = 500; - - this.enemiesBurned = 0; - this.enemiesExploded = 0; - - this.setNextKanisterSpawnScore = function () { - - if (this.score > 500) { - this.kanisterSpawnScore = 1000; - } - - if (this.score > 1000) { - this.kanisterSpawnScore = 1500; - } - - if (this.score > 1500) { - this.kanisterSpawnScore = 2500; - } - - if (this.score > 2500) { - this.kanisterSpawnScore = 5000; - } - - if (this.score > 5000) { - var dice = GameLib.Utils.GetRandomIntInclusive(1, 10); - - /** - * Max average spawn = 5.41 - * @type {number} - */ - dice += 6.41; - - /** - * 53 is one more than average score, in total - should be against your odds to win. - */ - this.kanisterSpawnScore = this.score + (dice * 53 * this.level); - } - - console.log('next kanister spawn score: ' + this.kanisterSpawnScore); - - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - event: 'nextKanisterSpawnScoreUpdate', - kanisterSpawnScore: this.kanisterSpawnScore - } - ); - }; - - 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.scene.meshes.map( - function (mesh) { - if (mesh.burningTreeParticleEngine) { - mesh.burning = false; - mesh.burnLife = 1; - mesh.burningTreeParticleEngine.enabled = false; - } - }.bind(this) - ); - - this.enemies = []; - - this.scores = []; - - 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.GET_GRAPHICS_IMPLEMENTATION, - null, - function (graphics) { - this.graphics = graphics - }.bind(this) - ); - - this.setLevelProperties = function () { - - this.prevLevel = this.level; - - this.level = Math.floor(this.enemiesExploded / 10) + 1; - - //this.enemySpawnInterval = Math.pow(this.level, 2) - 3 * this.level + 2; - - if (this.level === 1) { - this.enemySpawnInterval = 4; - } - - if (this.level === 2) { - this.enemySpawnInterval = 3; - } - - if (this.level === 3) { - this.enemySpawnInterval = 2; - } - - if (this.level > 3) { - this.enemySpawnInterval = 1.5; - } - - console.log('level : ' + this.level + ', spawn interval : ' + this.enemySpawnInterval); - - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - level: this.level, - enemySpawnInterval: this.enemySpawnInterval, - event: 'levelIncrease' - } - ); - }; - - - this.getNextMesh = function (meshType) { - - var mesh = null; - - for (var i = 0; i < this.meshes[meshType].length; i++) { - if (this.meshes[meshType][i].inUse === false) { - this.meshes[meshType][i].inUse = true; - mesh = this.meshes[meshType][i].mesh; - return mesh; - } - } - - return mesh; - } - - this.spawnEnemy = function (kanister) { - - var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); - - var meshTypeIndex; - - if (kanister) { - meshTypeIndex = 6; - } else { - meshTypeIndex = GameLib.Utils.GetRandomIntInclusive(1, 5); - } - - var meshType = null; - var speed = 1; - var score = 0; - var burnLife = 1; - var explodeLife = 1; - - if (meshTypeIndex === 1) { - meshType = 'bull'; - score = 10; - speed = 0.2; - } else if (meshTypeIndex === 2) { - meshType = 'star'; - score = 20; - speed = 0.3; - } else if (meshTypeIndex === 3) { - meshType = 'burger'; - score = 50; - speed = 0.4; - } else if (meshTypeIndex === 4) { - meshType = 'parcel'; - score = 75; - speed = 0.5; - } else if (meshTypeIndex === 5) { - meshType = 'santa'; - score = 100; - speed = 0.6; - } else if (meshTypeIndex === 6) { - meshType = 'kanister'; - score = 50; - speed = 0.7; - burnLife = 0; - explodeLife = 0; - } else { - console.warn('unknown mesh type index: ' + meshTypeIndex); - return; - } - - var mesh = this.getNextMesh(meshType); - - if (!mesh) { - console.log('buffer empty.. waiting a bit'); - return; - } - - mesh.burnLife = burnLife; - mesh.explodeLife = explodeLife; - mesh.instance.material.color.setRGB(1, 1, 1); - mesh.instance.material.opacity = 1; - mesh.visible = true; - mesh.updateInstance('visible'); - - if (kanister) { - - this.setNextKanisterSpawnScore(); - - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - event: 'kanisterCountUpdate', - kanisters: this.kanisters - } - ); - - } else { - this.enemiesSpawned++; - this.setLevelProperties(); - } - - var y = GameLib.Utils.GetRandomIntInclusive(2, 10); - - 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 - }; - - /** + this.enemies = []; + + this.scores = []; + + this.enemiesSpawned = 0; + + + this.leftLight.intensity = 0.3; + this.leftLight.updateInstance('intensity'); + this.rightLight.intensity = 0.3; + this.rightLight.updateInstance('intensity'); + + GameLib.Event.Emit( + GameLib.Event.GET_GRAPHICS_IMPLEMENTATION, + null, + function (graphics) { + this.graphics = graphics + }.bind(this) + ); + + this.setLevelProperties = function () { + + this.prevLevel = this.level; + + this.level = Math.floor(this.enemiesExploded / 10) + 1; + + //this.enemySpawnInterval = Math.pow(this.level, 2) - 3 * this.level + 2; + + if (this.level === 1) { + this.enemySpawnInterval = 4; + } + + if (this.level === 2) { + this.enemySpawnInterval = 3; + } + + if (this.level === 3) { + this.enemySpawnInterval = 2; + } + + if (this.level > 3) { + this.enemySpawnInterval = 1.5; + } + + console.log('level : ' + this.level + ', spawn interval : ' + this.enemySpawnInterval); + + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + level: this.level, + enemySpawnInterval: this.enemySpawnInterval, + event: 'levelIncrease' + } + ); + }; + + + this.getNextMesh = function (meshType) { + + var mesh = null; + + for (var i = 0; i < this.meshes[meshType].length; i++) { + if (this.meshes[meshType][i].inUse === false) { + this.meshes[meshType][i].inUse = true; + mesh = this.meshes[meshType][i].mesh; + return mesh; + } + } + + return mesh; + } + + this.spawnEnemy = function (kanister) { + + var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); + + var meshTypeIndex; + + if (kanister) { + meshTypeIndex = 6; + } else { + meshTypeIndex = GameLib.Utils.GetRandomIntInclusive(1, 5); + } + + var meshType = null; + var speed = 1; + var score = 0; + var burnLife = 1; + var explodeLife = 1; + + if (meshTypeIndex === 1) { + meshType = 'bull'; + score = 10; + speed = 0.2; + } else if (meshTypeIndex === 2) { + meshType = 'star'; + score = 20; + speed = 0.3; + } else if (meshTypeIndex === 3) { + meshType = 'burger'; + score = 50; + speed = 0.4; + } else if (meshTypeIndex === 4) { + meshType = 'parcel'; + score = 75; + speed = 0.5; + } else if (meshTypeIndex === 5) { + meshType = 'santa'; + score = 100; + speed = 0.6; + } else if (meshTypeIndex === 6) { + meshType = 'kanister'; + score = 50; + speed = 0.7; + burnLife = 0; + explodeLife = 0; + } else { + console.warn('unknown mesh type index: ' + meshTypeIndex); + return; + } + + var mesh = this.getNextMesh(meshType); + + if (!mesh) { + console.log('buffer empty.. waiting a bit'); + return; + } + + mesh.burnLife = burnLife; + mesh.explodeLife = explodeLife; + mesh.instance.material.color.setRGB(1, 1, 1); + mesh.instance.material.opacity = 1; + mesh.visible = true; + mesh.updateInstance('visible'); + + if (kanister) { + + this.setNextKanisterSpawnScore(); + + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + event: 'kanisterCountUpdate', + kanisters: this.kanisters + } + ); + + } else { + this.enemiesSpawned++; + this.setLevelProperties(); + } + + var y = GameLib.Utils.GetRandomIntInclusive(2, 10); + + 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 + }; + + /** * Link the enemy to the mesh */ - mesh.enemy = enemy; + mesh.enemy = enemy; - var distance = 100; - var angledistance = distance * Math.sin(Math.PI / 4); + var distance = 100; + var angledistance = distance * Math.sin(Math.PI / 4); - var life = 2.5 / speed; + var life = 2.5 / speed; - if (enemyType === 1) { - position.x = -distance; - life += 1.5 / speed; - velocity = {x: speed, y: 0, z: 0}; - } + 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 === 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 === 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 === 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}; - } + 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.updateInstance('position'); + enemy.mesh.position.x = position.x; + enemy.mesh.position.y = position.y; + enemy.mesh.position.z = position.z; + enemy.mesh.updateInstance('position'); - 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.updateInstance('quaternion'); + 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.updateInstance('quaternion'); - enemy.velocity = velocity; - enemy.rotation = rotation; + enemy.velocity = velocity; + enemy.rotation = rotation; - enemy.lifeTime = 0; - enemy.life = life; + enemy.lifeTime = 0; + enemy.life = life; - enemy.exploding = false; - enemy.burning = false; - enemy.burnLife = 1.5; - enemy.burnTime = 0; - enemy.explodingLife = 2; - enemy.meshType = meshType; - enemy.score = score * this.level; - enemy.isKanister = false; + enemy.exploding = false; + enemy.burning = false; + enemy.burnLife = 1.5; + enemy.burnTime = 0; + enemy.explodingLife = 2; + enemy.meshType = meshType; + enemy.score = score * this.level; + enemy.isKanister = false; - if (kanister) { - enemy.isKanister = true; - } else { - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - enemiesSpawned: this.enemiesSpawned, - enemy: enemy, - event: 'enemySpawned' - } - ); - } + if (kanister) { + enemy.isKanister = true; + } else { + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + enemiesSpawned: this.enemiesSpawned, + enemy: enemy, + event: 'enemySpawned' + } + ); + } - this.enemies.push(enemy); - }; + this.enemies.push(enemy); + }; - this.drawScore = function (enemy) { + this.drawScore = function (enemy) { - this.scoreMesh.materials[0].opacity = 1.0; - this.scoreMesh.materials[0].updateInstance('opacity'); + this.scoreMesh.materials[0].opacity = 1.0; + this.scoreMesh.materials[0].updateInstance('opacity'); - this.scoreMesh.position = enemy.mesh.position.clone(); - this.scoreMesh.updateInstance('position'); + this.scoreMesh.position = enemy.mesh.position.clone(); + this.scoreMesh.updateInstance('position'); - this.scoreMesh.instance.quaternion.copy(this.camera.instance.quaternion); + this.scoreMesh.instance.quaternion.copy(this.camera.instance.quaternion); - var context = this.scoreCanvas.instance.getContext('2d'); + var context = this.scoreCanvas.instance.getContext('2d'); - context.textBaseline = "middle"; + context.textBaseline = "middle"; - context.clearRect(0, 0, this.scoreCanvas.width, this.scoreCanvas.height); + context.clearRect(0, 0, this.scoreCanvas.width, this.scoreCanvas.height); - /** + /** * Write text */ - context.fillStyle = '#e0b899'; - context.font = '230pt BkBold'; - context.fillText(enemy.score, 0, this.scoreCanvas.height / 2); + context.fillStyle = '#e0b899'; + context.font = '230pt BkBold'; + context.fillText(enemy.score, 0, this.scoreCanvas.height / 2); - this.scoreTexture.instance.needsUpdate = true; + this.scoreTexture.instance.needsUpdate = true; - }.bind(this) + }.bind(this) - this.explodeMesh = function (mesh) { + this.explodeMesh = function (mesh) { - mesh.visible = false; + mesh.visible = false; - mesh.updateInstance('visible'); + mesh.updateInstance('visible'); - var sound = GameLib.Utils.GetRandomIntInclusive(1, 3); + var sound = GameLib.Utils.GetRandomIntInclusive(1, 3); - var name = 'Audio - Blast 1'; + var name = 'Audio - Blast 1'; - if (sound === 2) { - name = 'Audio - Blast 2'; - } + if (sound === 2) { + name = 'Audio - Blast 2'; + } - if (sound === 3) { - name = 'Audio - Blast 3'; - } + if (sound === 3) { + name = 'Audio - Blast 3'; + } - mesh.explodeParticleEngine.position.x = mesh.position.x; - mesh.explodeParticleEngine.position.y = mesh.position.y; - mesh.explodeParticleEngine.position.z = mesh.position.z; - mesh.explodeParticleEngine.updateInstance('position'); - mesh.explodeParticleEngine.enabled = true; + mesh.explodeParticleEngine.position.x = mesh.position.x; + mesh.explodeParticleEngine.position.y = mesh.position.y; + mesh.explodeParticleEngine.position.z = mesh.position.z; + mesh.explodeParticleEngine.updateInstance('position'); + mesh.explodeParticleEngine.enabled = true; - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name: name - } - ); - }; + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name: name + } + ); + }; - this.explode = function (mesh) { - - mesh.enemy.exploding = true; + this.explode = function (mesh) { - if (mesh.enemy.isKanister) { + mesh.enemy.exploding = true; - this.kanisters += 1; + if (mesh.enemy.isKanister) { - if (this.kanisters > 9) { - this.kanisters = 9; - } + this.kanisters += 1; - console.log('exploding kanister, total count: ' + this.kanisters); + if (this.kanisters > 9) { + this.kanisters = 9; + } - } else { + console.log('exploding kanister, total count: ' + this.kanisters); - console.log('exploding enemy'); + } else { - this.enemiesExploded += 1; - - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - enemy: mesh.enemy, - event: 'enemyExploded' - } - ); + console.log('exploding enemy'); - this.score += mesh.enemy.score; + this.enemiesExploded += 1; - this.drawScore(mesh.enemy); + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + enemy: mesh.enemy, + event: 'enemyExploded' + } + ); - console.log('score : ' + this.score); + this.score += mesh.enemy.score; - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - event: 'scoreUpdate', - score: this.score - } - ); - } + this.drawScore(mesh.enemy); - this.explodeMesh(mesh); - }; + console.log('score : ' + this.score); - this.burn = function (mesh) { + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + event: 'scoreUpdate', + score: this.score + } + ); + } - console.log('burning enemy ' + mesh.name); + this.explodeMesh(mesh); + }; - this.enemiesBurned += 1; - - mesh.enemy.burning = true; + this.burn = function (mesh) { - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - enemy: mesh.enemy, - event: 'enemyBurned' - } - ); + console.log('burning enemy ' + mesh.name); - mesh.smokeParticleEngine.position.x = mesh.position.x; - mesh.smokeParticleEngine.position.y = mesh.position.y; - mesh.smokeParticleEngine.position.z = mesh.position.z; - mesh.smokeParticleEngine.updateInstance('position'); - mesh.smokeParticleEngine.enabled = true; + this.enemiesBurned += 1; - mesh.fireParticleEngine.position.x = mesh.position.x; - mesh.fireParticleEngine.position.y = mesh.position.y; - mesh.fireParticleEngine.position.z = mesh.position.z; - mesh.fireParticleEngine.updateInstance('position'); - mesh.fireParticleEngine.enabled = true; + mesh.enemy.burning = true; - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name: 'Audio - Burning' - } - ); - }; + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + enemy: mesh.enemy, + event: 'enemyBurned' + } + ); - this.kill = function (enemy) { + mesh.smokeParticleEngine.position.x = mesh.position.x; + mesh.smokeParticleEngine.position.y = mesh.position.y; + mesh.smokeParticleEngine.position.z = mesh.position.z; + mesh.smokeParticleEngine.updateInstance('position'); + mesh.smokeParticleEngine.enabled = true; - var found = false; + mesh.fireParticleEngine.position.x = mesh.position.x; + mesh.fireParticleEngine.position.y = mesh.position.y; + mesh.fireParticleEngine.position.z = mesh.position.z; + mesh.fireParticleEngine.updateInstance('position'); + mesh.fireParticleEngine.enabled = true; - for (var i = 0; i < 5; i++) { - if (this.meshes[enemy.meshType][i].mesh === enemy.mesh) { - found = true; - this.meshes[enemy.meshType][i].inUse = false; - this.meshes[enemy.meshType][i].mesh.visible = false; - this.meshes[enemy.meshType][i].mesh.updateInstance('visible'); - } - } + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name: 'Audio - Burning' + } + ); + }; - if (!found) { - console.warn('could not find mesh to kill'); - } + this.kill = function (enemy) { - if (enemy.mesh.smokeParticleEngine) { - enemy.mesh.smokeParticleEngine.enabled = false; - } + var found = false; - if (enemy.mesh.fireParticleEngine) { - enemy.mesh.fireParticleEngine.enabled = false; - } + for (var i = 0; i < 5; i++) { + if (this.meshes[enemy.meshType][i].mesh === enemy.mesh) { + found = true; + this.meshes[enemy.meshType][i].inUse = false; + this.meshes[enemy.meshType][i].mesh.visible = false; + this.meshes[enemy.meshType][i].mesh.updateInstance('visible'); + } + } - if (enemy.mesh.explodeParticleEngine) { - enemy.mesh.explodeParticleEngine.enabled = false; - } + if (!found) { + console.warn('could not find mesh to kill'); + } - }.bind(this); + if (enemy.mesh.smokeParticleEngine) { + enemy.mesh.smokeParticleEngine.enabled = false; + } - this.burnTree = function (mesh) { + if (enemy.mesh.fireParticleEngine) { + enemy.mesh.fireParticleEngine.enabled = false; + } - if (mesh.burning) { - /** + if (enemy.mesh.explodeParticleEngine) { + enemy.mesh.explodeParticleEngine.enabled = false; + } + + }.bind(this); + + this.burnTree = function (mesh) { + + if (mesh.burning) { + /** * Do nothing, this tree is burning */ - } else { + } else { - mesh.burning = true; + mesh.burning = true; - this.treesBurning++; + this.treesBurning++; - 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' - } - ); - } + 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' + } + ); + } - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - event: 'treeBurned', - treesBurning: this.treesBurning, - treesBurningToStart: this.treesBurningToStart - } - ); + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + event: 'treeBurned', + treesBurning: this.treesBurning, + treesBurningToStart: this.treesBurningToStart + } + ); - this.minimumRendererRed += 0.01; + this.minimumRendererRed += 0.01; + + if (mesh.position.x < 0) { + this.leftLight.intensity += data.delta * 2.5; - this.fog.density -= 0.00025; - if (this.fog.density < 0.0055) { - this.fog.density = 0.0055; - } - this.fog.updateInstance('density'); + if (this.leftLight.intensity >= 1) { + this.leftLight.intensity = 1; + } - if (mesh.position.x < 0) { - this.leftLight.intensity += data.delta * 2.5; + this.leftLight.updateInstance('intensity'); - if (this.leftLight.intensity >= 1) { - this.leftLight.intensity = 1; - } + } else { + this.rightLight.intensity += data.delta * 2.5; - this.leftLight.updateInstance('intensity'); + if (this.rightLight.intensity >= 1) { + this.rightLight.intensity = 1; + } - } else { - this.rightLight.intensity += data.delta * 2.5; + this.rightLight.updateInstance('intensity'); - if (this.rightLight.intensity >= 1) { - this.rightLight.intensity = 1; - } + } - this.rightLight.updateInstance('intensity'); + mesh.burningTreeParticleEngine.enabled = true; - } + GameLib.Event.Emit( + GameLib.Event.PLAY_AUDIO, + { + name: 'Audio - Burning' + } + ); + } + }; - mesh.burningTreeParticleEngine.enabled = true; + GameLib.Event.Emit( + GameLib.Event.GAME_STARTED, + { + game: this + } + ); + } - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, - { - name: 'Audio - Burning' - } - ); - } - }; + this.totalTime += data.delta; + this.enemySpawnTime += data.delta; - GameLib.Event.Emit( - GameLib.Event.GAME_STARTED, - { - game: this - } - ); -} + this.scoreMesh.materials[0].opacity -= data.delta * 0.5; + if (this.scoreMesh.materials[0].opacity < 0) { + this.scoreMesh.materials[0].opacity = 0; + } + this.scoreMesh.materials[0].updateInstance('opacity'); -this.totalTime += data.delta; -this.enemySpawnTime += data.delta; + this.scene.meshes.map( + function (mesh) { + if (mesh.instance.material.emissive) { + mesh.instance.material.emissive.sub(this.toRed); + } + }.bind(this) + ); -this.scoreMesh.materials[0].opacity -= data.delta * 0.5; -if (this.scoreMesh.materials[0].opacity < 0) { - this.scoreMesh.materials[0].opacity = 0; -} -this.scoreMesh.materials[0].updateInstance('opacity'); + if (this.mouseIsDown) { -this.scene.meshes.map( - function (mesh) { - if (mesh.instance.material.emissive) { - mesh.instance.material.emissive.sub(this.toRed); - } - }.bind(this) -); + this.kanisterTime += data.delta * 1.125; -if (this.mouseIsDown) { + this.renderer.clearColor.r += 0.01; + if (this.renderer.clearColor.r > 0.45) { + this.renderer.clearColor.r = 0.45; + } + this.renderer.updateInstance('clearColor'); - this.kanisterTime += data.delta * 1.125; + this.throwerLight.intensity += 0.05; + if (this.throwerLight.intensity > 2) { + this.throwerLight.intensity = 2; + } + this.throwerLight.updateInstance('intensity'); - this.renderer.clearColor.r += 0.01; - if (this.renderer.clearColor.r > 0.45) { - this.renderer.clearColor.r = 0.45; - } - this.renderer.updateInstance('clearColor'); + var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes); + intersects.map( + function (intersect) { - this.throwerLight.intensity += 0.05; - if (this.throwerLight.intensity > 2) { - this.throwerLight.intensity = 2; - } - this.throwerLight.updateInstance('intensity'); + var mesh = intersect.mesh; - var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes); - intersects.map( - function (intersect) { + 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('Kanister') !== -1 //kanister + ) { - var mesh = intersect.mesh; + if (mesh.materials[0].name.indexOf('Trees') === -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 - mesh.name.indexOf('Kanister') !== -1 //kanister - ) { + if (!mesh.enemy.burning) { - if (mesh.materials[0].name.indexOf('Trees') === -1) { + mesh.burnLife -= data.delta * 1.5; - if (!mesh.enemy.burning) { + if (mesh.burnLife < 0) { + mesh.burnLife = 0; + this.burn(mesh); + } - mesh.burnLife -= data.delta * 1.5; + mesh.instance.material.color.setRGB( + mesh.burnLife, + mesh.burnLife, + mesh.burnLife + ); - if (mesh.burnLife < 0) { - mesh.burnLife = 0; - this.burn(mesh); - } + } else { - mesh.instance.material.color.setRGB( - mesh.burnLife, - mesh.burnLife, - mesh.burnLife - ); + if (!mesh.enemy.exploding) { + mesh.explodeLife -= data.delta * 2.5; + if (mesh.explodeLife < 0) { + mesh.explodeLife = 0; + this.explode(mesh); + } - } else { + if (mesh.instance.material.emissive) { + mesh.instance.material.emissive.setRGB( + 1 - mesh.explodeLife, + 0, + 0 + ); + } + } + } - if (!mesh.enemy.exploding) { - mesh.explodeLife -= data.delta * 2.5; - if (mesh.explodeLife < 0) { - mesh.explodeLife = 0; - this.explode(mesh); - } + } else { - if (mesh.instance.material.emissive) { - mesh.instance.material.emissive.setRGB( - 1 - mesh.explodeLife, - 0, - 0 - ); - } - } - } - - } else { - - /** + /** * This happens to trees */ - if (GameLib.Utils.UndefinedOrNull(mesh.burnLife)) { - mesh.burnLife = 1; - mesh.burning = false; - } + if (GameLib.Utils.UndefinedOrNull(mesh.burnLife)) { + mesh.burnLife = 1; + mesh.burning = false; + } - if (!mesh.burning) { + if (!mesh.burning) { - mesh.burnLife -= data.delta * 2; + mesh.burnLife -= data.delta * 2; - if (mesh.burnLife <= 0) { - mesh.burnLife = 0; - this.burnTree(mesh); - } + if (mesh.burnLife <= 0) { + mesh.burnLife = 0; + this.burnTree(mesh); + } - if (mesh.instance.material.emissive) { - mesh.instance.material.emissive.setRGB( - 1 - mesh.burnLife, - 0, - 0 - ); - } - } - } - } - }.bind(this) - ); + if (mesh.instance.material.emissive) { + mesh.instance.material.emissive.setRGB( + 1 - mesh.burnLife, + 0, + 0 + ); + } + } + } + } + }.bind(this) + ); -} -else { - this.kanisterTime += (data.delta * this.kanisterLeakTime); + } + else { + this.kanisterTime += (data.delta * this.kanisterLeakTime); - this.renderer.clearColor.r -= data.delta; - if (this.renderer.clearColor.r < this.minimumRendererRed) { - this.renderer.clearColor.r = this.minimumRendererRed; - } - this.renderer.updateInstance('clearColor'); + this.renderer.clearColor.r -= data.delta; + if (this.renderer.clearColor.r < this.minimumRendererRed) { + this.renderer.clearColor.r = this.minimumRendererRed; + } + this.renderer.updateInstance('clearColor'); - this.throwerLight.intensity -= data.delta * 3; - if (this.throwerLight.intensity < 0) { - this.throwerLight.intensity = 0; - } - this.throwerLight.updateInstance('intensity'); -} + this.throwerLight.intensity -= data.delta * 3; + if (this.throwerLight.intensity < 0) { + this.throwerLight.intensity = 0; + } + this.throwerLight.updateInstance('intensity'); + } -var used = this.kanisterTime / this.kanisterLife; + var used = this.kanisterTime / this.kanisterLife; -GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - event: 'fuelUsed', - used: used, - percentage: Math.round(used * 100) + '%', - kanisters: this.kanisters - } -); + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + event: 'fuelUsed', + used: used, + percentage: Math.round(used * 100) + '%', + kanisters: this.kanisters + } + ); -if (this.kanisterTime > this.kanisterLife) { + if (this.kanisterTime > this.kanisterLife) { - this.kanisterTime = 0; - this.kanisters -= 1; + this.kanisterTime = 0; + this.kanisters -= 1; - console.log('kanister count: ' + this.kanisters); + console.log('kanister count: ' + this.kanisters); - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - event: 'kanisterCountUpdate', - kanisters: this.kanisters - } - ); + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + event: 'kanisterCountUpdate', + kanisters: this.kanisters + } + ); - if (this.kanisters < 0) { - console.log('no more kanisters'); - GameLib.Event.Emit( - GameLib.Event.GAME_OVER, - { - game: this - } - ); - } -} + if (this.kanisters < 0) { + console.log('no more kanisters'); + GameLib.Event.Emit( + GameLib.Event.GAME_OVER, + { + game: this + } + ); + } + } -if (this.enemySpawnTime > this.enemySpawnInterval && this.running) { - this.enemySpawnTime = 0; - this.spawnEnemy(false); -} + if (this.enemySpawnTime > this.enemySpawnInterval && this.running) { + this.enemySpawnTime = 0; + this.spawnEnemy(false); + } -this.enemies = this.enemies.reduce( - function (result, enemy) { + this.enemies = this.enemies.reduce( + function (result, enemy) { - /** + /** * 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; - enemy.mesh.updateInstance('position'); + 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; + enemy.mesh.updateInstance('position'); - enemy.mesh.quaternion.angle += enemy.rotation.angle * data.delta * 60; - enemy.mesh.updateInstance('quaternion'); + enemy.mesh.quaternion.angle += enemy.rotation.angle * data.delta * 60; + enemy.mesh.updateInstance('quaternion'); - /** + /** * Update its lifetime */ - enemy.lifeTime += data.delta; - if (enemy.lifeTime > enemy.life) { + enemy.lifeTime += data.delta; + if (enemy.lifeTime > enemy.life) { - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - event: 'enemyLifetimeReached', - enemy: enemy - } - ); + GameLib.Event.Emit( + GameLib.Event.GAME_DATA, + { + event: 'enemyLifetimeReached', + enemy: enemy + } + ); - /** + /** * We only remove the things we cloned */ - this.kill(enemy); - return result; - } + this.kill(enemy); + return result; + } - if (enemy.exploding === true) { + 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; + } - if (enemy.burning) { + if (enemy.burning) { - if (!enemy.exploding) { - enemy.burnTime += data.delta; - if (enemy.burnTime > enemy.burnLife) { - this.explode(enemy.mesh); - } - } + if (!enemy.exploding) { + enemy.burnTime += data.delta; + if (enemy.burnTime > enemy.burnLife) { + this.explode(enemy.mesh); + } + } - 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.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'); - } + 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; - } + result.push(enemy); + return result; + } - result.push(enemy); - return result; + result.push(enemy); + return result; - }.bind(this), - [] -); + }.bind(this), + [] + ); -if (this.score > this.kanisterSpawnScore) { - this.spawnEnemy(true); -} + if (this.score > this.kanisterSpawnScore) { + this.spawnEnemy(true); + } -return null;//# sourceURL=beforeRender.js + return null;//# sourceURL=beforeRender.js \ No newline at end of file