From 5e788b5bd699152a0688246d8198a2d7ec695c0f Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 27 Nov 2017 14:37:38 +0100 Subject: [PATCH] Update: CC - Before Render - Moorcow (qemp4een6t.js) 694 bytes modified --- qemp4een6t.js | 421 +++++++++++++++++++++++--------------------------- 1 file changed, 197 insertions(+), 224 deletions(-) diff --git a/qemp4een6t.js b/qemp4een6t.js index 4e93c38..d556886 100644 --- a/qemp4een6t.js +++ b/qemp4een6t.js @@ -1,4 +1,5 @@ + if (!this.entityLoaded) { return; } @@ -12,7 +13,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { GameLib.Event.Emit( GameLib.Event.PLAY_AUDIO, { - name : 'Audio - Xmas' + name: 'Audio - Xmas' } ); @@ -22,14 +23,14 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { this.blastSubscription = GameLib.Event.Subscribe( GameLib.Event.AUDIO_ENDED, - function(data) { + function (data) { if (data.audio.name.indexOf('Blast') !== -1) { - var play = GameLib.Utils.GetRandomIntInclusive(1,5); + var play = GameLib.Utils.GetRandomIntInclusive(1, 5); if (play === 1) { GameLib.Event.Emit( GameLib.Event.PLAY_AUDIO, { - name : 'Audio - Ho ho ho' + name: 'Audio - Ho ho ho' } ); } @@ -45,6 +46,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { 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; @@ -86,7 +88,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { this.kanisterLeakTime = 0.1; this.kanisterSpawnScore = 50; - this.setNextKanisterSpawnScore = function() { + this.setNextKanisterSpawnScore = function () { this.kanisterSpawnScore = this.score + 100; @@ -135,14 +137,12 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'nextKanisterSpawnScoreUpdate', - kanisterSpawnScore : this.kanisterSpawnScore + event: 'nextKanisterSpawnScoreUpdate', + kanisterSpawnScore: this.kanisterSpawnScore } ); }; - this.fuelFinished = false; - this.level = 1; this.enemySpawnInterval = 5; @@ -152,19 +152,18 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { if (this.enemies instanceof Array && this.enemies.length !== 0) { this.enemies.map( - function(enemy) { + function (enemy) { this.kill(enemy); }.bind(this) ) } this.scene.meshes.map( - function(mesh) { + function (mesh) { if (mesh.burningTreeParticleEngine) { mesh.burning = false; mesh.burnLife = 1; - mesh.burningTreeParticleEngine.remove(); - mesh.burningTreeParticleEngine = null; + mesh.burningTreeParticleEngine.enabled = false; } }.bind(this) ); @@ -185,12 +184,12 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { GameLib.Event.Emit( GameLib.Event.GET_GRAPHICS_IMPLEMENTATION, null, - function(graphics) { + function (graphics) { this.graphics = graphics }.bind(this) ); - this.setLevelProperties = function() { + this.setLevelProperties = function () { this.prevLevel = this.level; @@ -212,26 +211,108 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { this.enemySpawnInterval = 1.5; } - console.log('level : ' + this.level +', spawn interval : ' + this.enemySpawnInterval); + console.log('level : ' + this.level + ', spawn interval : ' + this.enemySpawnInterval); GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - level : this.level, - enemySpawnInterval : this.enemySpawnInterval, - event : 'levelIncrease' + level: this.level, + enemySpawnInterval: this.enemySpawnInterval, + event: 'levelIncrease' } ); }; - this.spawnEnemy = function(kanister) { + this.getNextMesh = function (meshType) { - var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); - var meshType = GameLib.Utils.GetRandomIntInclusive(1, 5); + 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; + } + + this.spawnEnemy = function (kanister) { + + var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); + + var meshTypeIndex; if (kanister) { - meshType = 6; + 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.3; + } else if (meshTypeIndex === 2) { + meshType = 'star'; + score = 20; + speed = 0.4; + } else if (meshTypeIndex === 3) { + meshType = 'burger'; + score = 50; + speed = 0.45; + } 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(); @@ -239,77 +320,27 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { var y = GameLib.Utils.GetRandomIntInclusive(2, 10); - var speed = 1; - - var score = 10; - - var material = null; - - var mesh = null; - if (meshType === 1) { - mesh = this.bull.clone(); - material = this.bull.materials[0].clone(); - speed = 0.3; - } else if (meshType === 2) { - mesh = this.star.clone(); - score = 20; - material = this.star.materials[0].clone(); - speed = 0.4; - } else if (meshType === 3) { - mesh = this.burger.clone(); - score = 50; - material = this.burger.materials[0].clone(); - speed = 0.45; - } else if (meshType === 4) { - mesh = this.parcel.clone(); - score = 75; - material = this.parcel.materials[0].clone(); - speed = 0.5; - } else if (meshType === 5) { - mesh = this.santa.clone(); - score = 100; - material = this.santa.materials[0].clone(); - speed = 0.6; - } else if (meshType === 6) { - mesh = this.kanister.clone(); - score = 100; - material = this.kanister.materials[0].clone(); - speed = 0.7; - } - else { - console.log('unknown mesh type : ' + meshType); - } - - mesh.materials = [material]; - mesh.updateInstance('materials'); - - mesh.visible = true; - mesh.updateInstance('visible'); - - mesh.burnLife = 1; - mesh.explodeLife = 1; - 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 + 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 angle = GameLib.Utils.GetRandomIntInclusive(1, 100) * 0.001; - var position = {x : 0, y: y, z :0}; + var position = {x: 0, y: y, z: 0}; var rotation = { - axis : axis, - angle : angle + axis: axis, + angle: angle }; var enemy = { - mesh : mesh + mesh: mesh }; /** @@ -325,31 +356,31 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { if (enemyType === 1) { position.x = -distance; life += 3 / speed; - velocity = {x:speed,y:0,z:0}; + velocity = {x: speed, y: 0, z: 0}; } if (enemyType === 2) { position.x = distance; life += 3 / speed; - velocity = {x:-speed,y:0,z:0}; + velocity = {x: -speed, y: 0, z: 0}; } if (enemyType === 3) { position.x = -angledistance; position.z = -angledistance; - velocity = {x:speed,y:0,z:speed}; + velocity = {x: speed, y: 0, z: speed}; } if (enemyType === 4) { position.x = angledistance; position.z = -angledistance; - velocity = {x:-speed,y:0,z:speed}; + velocity = {x: -speed, y: 0, z: speed}; } if (enemyType === 5) { position.x = 0; position.z = -distance; - velocity = {x:0,y:0,z:speed}; + velocity = {x: 0, y: 0, z: speed}; } enemy.mesh.position.x = position.x; @@ -382,7 +413,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { if (kanister) { enemy.isKanister = true; } else { - GameLib.Event.Emit( GameLib.Event.GAME_DATA, { @@ -396,24 +426,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { this.enemies.push(enemy); }; - this.spawnKanister = function() { - - console.log('spawning kanister'); - - this.setNextKanisterSpawnScore(); - - GameLib.Event.Emit( - GameLib.Event.GAME_DATA, - { - event : 'kanisterCountUpdate', - kanisters : this.kanisters - } - ); - - this.spawnEnemy(true); - }; - - this.drawScore = function(enemy) { + this.drawScore = function (enemy) { this.scoreMesh.materials[0].opacity = 1.0; this.scoreMesh.materials[0].updateInstance('opacity'); @@ -427,26 +440,26 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { 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.fillText(enemy.score, 0, this.scoreCanvas.height / 2); this.scoreTexture.instance.needsUpdate = true; }.bind(this) - this.explodeMesh = function(mesh) { + this.explodeMesh = function (mesh) { mesh.visible = false; mesh.updateInstance('visible'); - var sound = GameLib.Utils.GetRandomIntInclusive(1,3); + var sound = GameLib.Utils.GetRandomIntInclusive(1, 3); var name = 'Audio - Blast 1'; @@ -458,24 +471,21 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { name = 'Audio - Blast 3'; } - var explodeParticleEngine = this.explodeParticleEngine.clone(); - explodeParticleEngine.position.x = mesh.position.x; - explodeParticleEngine.position.y = mesh.position.y; - explodeParticleEngine.position.z = mesh.position.z; - explodeParticleEngine.updateInstance('position'); - explodeParticleEngine.enabled = true; - mesh.explodeParticleEngine = explodeParticleEngine; + 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 + name: name } ); - }; - this.explode = function(mesh) { + this.explode = function (mesh) { mesh.enemy.exploding = true; @@ -502,20 +512,20 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'scoreUpdate', - score : this.score + event: 'scoreUpdate', + score: this.score } ); if (this.score > this.kanisterSpawnScore) { - this.spawnKanister(); + this.spawnEnemy(true); } GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - enemy : mesh.enemy, - event : 'enemyExploded' + enemy: mesh.enemy, + event: 'enemyExploded' } ); } @@ -523,7 +533,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { this.explodeMesh(mesh); }; - this.burn = function(mesh) { + this.burn = function (mesh) { console.log('burning enemy ' + mesh.name); @@ -532,74 +542,63 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - enemy : mesh.enemy, - event : 'enemyBurned' + enemy: mesh.enemy, + event: 'enemyBurned' } ); - var smokeParticleEngine = this.smokeParticleEngine.clone(); - smokeParticleEngine.position = mesh.position.clone(); - smokeParticleEngine.updateInstance('position'); - smokeParticleEngine.enabled = true; - mesh.smokeParticleEngine = smokeParticleEngine; + 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 fireParticleEngine = this.fireParticleEngine.clone(); - fireParticleEngine.position = mesh.position.clone(); - fireParticleEngine.updateInstance('position'); - fireParticleEngine.enabled = true; - mesh.fireParticleEngine = fireParticleEngine; + 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; GameLib.Event.Emit( GameLib.Event.PLAY_AUDIO, { - name : 'Audio - Burning' + name: 'Audio - Burning' } ); }; - this.kill = function(enemy) { + this.kill = function (enemy) { - /** - * We only remove the things we cloned - */ - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component : enemy.mesh.materials[0] + var found = 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'); } - ); + } - 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 (!found) { + console.warn('could not find mesh to kill'); + } if (enemy.mesh.smokeParticleEngine) { - enemy.mesh.smokeParticleEngine.remove(); - enemy.mesh.smokeParticleEngine = null; + enemy.mesh.smokeParticleEngine.enabled = false; } if (enemy.mesh.fireParticleEngine) { - enemy.mesh.fireParticleEngine.remove(); - enemy.mesh.fireParticleEngine = null; + enemy.mesh.fireParticleEngine.enabled = false; } if (enemy.mesh.explodeParticleEngine) { - enemy.mesh.explodeParticleEngine.remove(); - enemy.mesh.explodeParticleEngine = null; + enemy.mesh.explodeParticleEngine.enabled = false; } - }; + }.bind(this); - this.burnTree = function(mesh) { + this.burnTree = function (mesh) { if (mesh.burning) { /** @@ -619,8 +618,8 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'gameRunning', - message : 'we have enough trees burning now to start - the enemy will spawn now' + event: 'gameRunning', + message: 'we have enough trees burning now to start - the enemy will spawn now' } ); } @@ -628,9 +627,9 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'treeBurned', - treesBurning : this.treesBurning, - treesBurningToStart : this.treesBurningToStart + event: 'treeBurned', + treesBurning: this.treesBurning, + treesBurningToStart: this.treesBurningToStart } ); @@ -662,17 +661,12 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { } - 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.burningTreeParticleEngine.enabled = true; GameLib.Event.Emit( GameLib.Event.PLAY_AUDIO, { - name : 'Audio - Burning' + name: 'Audio - Burning' } ); } @@ -681,7 +675,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) { GameLib.Event.Emit( GameLib.Event.GAME_STARTED, { - game : this + game: this } ); } @@ -697,24 +691,14 @@ this.scoreMesh.materials[0].updateInstance('opacity'); 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); - } + if (mesh.instance.material.emissive) { + mesh.instance.material.emissive.sub(this.toRed); } }.bind(this) ); -if (this.mouseIsDown) -{ +if (this.mouseIsDown) { + this.kanisterTime += data.delta; this.renderer.clearColor.r += 0.01; @@ -731,29 +715,20 @@ if (this.mouseIsDown) var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes); intersects.map( - function(intersect) { + function (intersect) { var mesh = intersect.mesh; - if (mesh.name.indexOf('Kanister') !== -1) { - this.explode(mesh); - 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('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('Tree - Small') !== -1 ||//tree small + mesh.name.indexOf('Kanister') !== -1 //kanister ) { if (mesh.materials[0].name.indexOf('Trees') === -1) { @@ -825,8 +800,7 @@ if (this.mouseIsDown) ); } -else -{ +else { this.kanisterTime += (data.delta * this.kanisterLeakTime); this.renderer.clearColor.r -= data.delta; @@ -847,10 +821,10 @@ 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 + event: 'fuelUsed', + used: used, + percentage: Math.round(used * 100) + '%', + kanisters: this.kanisters } ); @@ -862,8 +836,8 @@ if (this.kanisterTime > this.kanisterLife) { GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'kanisterCountUpdate', - kanisters : this.kanisters + event: 'kanisterCountUpdate', + kanisters: this.kanisters } ); @@ -871,7 +845,7 @@ if (this.kanisterTime > this.kanisterLife) { GameLib.Event.Emit( GameLib.Event.GAME_OVER, { - game : this + game: this } ); } @@ -879,12 +853,11 @@ if (this.kanisterTime > this.kanisterLife) { if (this.enemySpawnTime > this.enemySpawnInterval && this.running) { this.enemySpawnTime = 0; - this.spawnEnemy(); + this.spawnEnemy(false); } this.enemies = this.enemies.reduce( - - function(result, enemy) { + function (result, enemy) { /** * Update enemy position and rotation @@ -906,8 +879,8 @@ this.enemies = this.enemies.reduce( GameLib.Event.Emit( GameLib.Event.GAME_DATA, { - event : 'enemyLifetimeReached', - enemy : enemy + event: 'enemyLifetimeReached', + enemy: enemy } ); @@ -960,7 +933,7 @@ this.enemies = this.enemies.reduce( result.push(enemy); return result; } - + result.push(enemy); return result; @@ -968,5 +941,5 @@ this.enemies = this.enemies.reduce( [] ); -return null; -//# sourceURL=beforeRender.js +return null;//# sourceURL=beforeRender.js +