Update: CC - Before Render - Moorcow (qemp4een6t.js) 694 bytes modified

beta.r3js.org
-=yb4f310 2017-11-27 14:37:38 +01:00
parent c75b1f6df2
commit 5e788b5bd6
1 changed files with 197 additions and 224 deletions

View File

@ -1,4 +1,5 @@
if (!this.entityLoaded) { if (!this.entityLoaded) {
return; return;
} }
@ -45,6 +46,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
this.camera = this.entityLoaded.camera; this.camera = this.entityLoaded.camera;
this.burger = this.entityLoaded.burger; this.burger = this.entityLoaded.burger;
this.parcel = this.entityLoaded.parcel; this.parcel = this.entityLoaded.parcel;
this.meshes = this.entityLoaded.meshes;
this.renderer = this.entityLoaded.renderer; this.renderer = this.entityLoaded.renderer;
this.raycaster = this.entityLoaded.raycaster; this.raycaster = this.entityLoaded.raycaster;
this.kanister = this.entityLoaded.kanister; this.kanister = this.entityLoaded.kanister;
@ -141,8 +143,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
); );
}; };
this.fuelFinished = false;
this.level = 1; this.level = 1;
this.enemySpawnInterval = 5; this.enemySpawnInterval = 5;
@ -163,8 +163,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
if (mesh.burningTreeParticleEngine) { if (mesh.burningTreeParticleEngine) {
mesh.burning = false; mesh.burning = false;
mesh.burnLife = 1; mesh.burnLife = 1;
mesh.burningTreeParticleEngine.remove(); mesh.burningTreeParticleEngine.enabled = false;
mesh.burningTreeParticleEngine = null;
} }
}.bind(this) }.bind(this)
); );
@ -225,13 +224,95 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
}; };
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;
}
this.spawnEnemy = function (kanister) { this.spawnEnemy = function (kanister) {
var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5);
var meshType = GameLib.Utils.GetRandomIntInclusive(1, 5);
var meshTypeIndex;
if (kanister) { 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 { } else {
this.enemiesSpawned++; this.enemiesSpawned++;
this.setLevelProperties(); this.setLevelProperties();
@ -239,56 +320,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
var y = GameLib.Utils.GetRandomIntInclusive(2, 10); 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 velocity = null;
var axis = new GameLib.API.Vector3( var axis = new GameLib.API.Vector3(
@ -382,7 +413,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
if (kanister) { if (kanister) {
enemy.isKanister = true; enemy.isKanister = true;
} else { } else {
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.GAME_DATA, GameLib.Event.GAME_DATA,
{ {
@ -396,23 +426,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
this.enemies.push(enemy); 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].opacity = 1.0;
@ -458,13 +471,11 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
name = 'Audio - Blast 3'; name = 'Audio - Blast 3';
} }
var explodeParticleEngine = this.explodeParticleEngine.clone(); mesh.explodeParticleEngine.position.x = mesh.position.x;
explodeParticleEngine.position.x = mesh.position.x; mesh.explodeParticleEngine.position.y = mesh.position.y;
explodeParticleEngine.position.y = mesh.position.y; mesh.explodeParticleEngine.position.z = mesh.position.z;
explodeParticleEngine.position.z = mesh.position.z; mesh.explodeParticleEngine.updateInstance('position');
explodeParticleEngine.updateInstance('position'); mesh.explodeParticleEngine.enabled = true;
explodeParticleEngine.enabled = true;
mesh.explodeParticleEngine = explodeParticleEngine;
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.PLAY_AUDIO, GameLib.Event.PLAY_AUDIO,
@ -472,7 +483,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
name: name name: name
} }
); );
}; };
this.explode = function (mesh) { this.explode = function (mesh) {
@ -508,7 +518,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
); );
if (this.score > this.kanisterSpawnScore) { if (this.score > this.kanisterSpawnScore) {
this.spawnKanister(); this.spawnEnemy(true);
} }
GameLib.Event.Emit( GameLib.Event.Emit(
@ -537,17 +547,17 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
} }
); );
var smokeParticleEngine = this.smokeParticleEngine.clone(); mesh.smokeParticleEngine.position.x = mesh.position.x;
smokeParticleEngine.position = mesh.position.clone(); mesh.smokeParticleEngine.position.y = mesh.position.y;
smokeParticleEngine.updateInstance('position'); mesh.smokeParticleEngine.position.z = mesh.position.z;
smokeParticleEngine.enabled = true; mesh.smokeParticleEngine.updateInstance('position');
mesh.smokeParticleEngine = smokeParticleEngine; mesh.smokeParticleEngine.enabled = true;
var fireParticleEngine = this.fireParticleEngine.clone(); mesh.fireParticleEngine.position.x = mesh.position.x;
fireParticleEngine.position = mesh.position.clone(); mesh.fireParticleEngine.position.y = mesh.position.y;
fireParticleEngine.updateInstance('position'); mesh.fireParticleEngine.position.z = mesh.position.z;
fireParticleEngine.enabled = true; mesh.fireParticleEngine.updateInstance('position');
mesh.fireParticleEngine = fireParticleEngine; mesh.fireParticleEngine.enabled = true;
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.PLAY_AUDIO, GameLib.Event.PLAY_AUDIO,
@ -559,45 +569,34 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
this.kill = function (enemy) { this.kill = function (enemy) {
/** var found = false;
* We only remove the things we cloned
*/
GameLib.Event.Emit(
GameLib.Event.REMOVE_COMPONENT,
{
component : enemy.mesh.materials[0]
}
);
GameLib.Event.Emit( for (var i = 0; i < 5; i++) {
GameLib.Event.REMOVE_COMPONENT, if (this.meshes[enemy.meshType][i].mesh === enemy.mesh) {
{ found = true;
component : enemy.mesh this.meshes[enemy.meshType][i].inUse = false;
this.meshes[enemy.meshType][i].mesh.visible = false;
this.meshes[enemy.meshType][i].mesh.updateInstance('visible');
}
} }
);
/** if (!found) {
* Also dispose of the THREE.js objects console.warn('could not find mesh to kill');
*/ }
enemy.mesh.instance.geometry.dispose();
enemy.mesh.instance.material.dispose();
if (enemy.mesh.smokeParticleEngine) { if (enemy.mesh.smokeParticleEngine) {
enemy.mesh.smokeParticleEngine.remove(); enemy.mesh.smokeParticleEngine.enabled = false;
enemy.mesh.smokeParticleEngine = null;
} }
if (enemy.mesh.fireParticleEngine) { if (enemy.mesh.fireParticleEngine) {
enemy.mesh.fireParticleEngine.remove(); enemy.mesh.fireParticleEngine.enabled = false;
enemy.mesh.fireParticleEngine = null;
} }
if (enemy.mesh.explodeParticleEngine) { if (enemy.mesh.explodeParticleEngine) {
enemy.mesh.explodeParticleEngine.remove(); enemy.mesh.explodeParticleEngine.enabled = false;
enemy.mesh.explodeParticleEngine = null;
} }
}; }.bind(this);
this.burnTree = function (mesh) { this.burnTree = function (mesh) {
@ -662,12 +661,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
} }
var burningTreeParticleEngine = this.burningTreeParticleEngine.clone(); mesh.burningTreeParticleEngine.enabled = true;
burningTreeParticleEngine.position = mesh.position.clone();
burningTreeParticleEngine.position.y += mesh.dimensions.y + 5;
burningTreeParticleEngine.updateInstance('position');
burningTreeParticleEngine.enabled = true;
mesh.burningTreeParticleEngine = burningTreeParticleEngine;
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.PLAY_AUDIO, GameLib.Event.PLAY_AUDIO,
@ -697,24 +691,14 @@ this.scoreMesh.materials[0].updateInstance('opacity');
this.scene.meshes.map( this.scene.meshes.map(
function(mesh) { 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) { if (mesh.instance.material.emissive) {
mesh.instance.material.emissive.sub(this.toRed); mesh.instance.material.emissive.sub(this.toRed);
} }
}
}.bind(this) }.bind(this)
); );
if (this.mouseIsDown) if (this.mouseIsDown) {
{
this.kanisterTime += data.delta; this.kanisterTime += data.delta;
this.renderer.clearColor.r += 0.01; this.renderer.clearColor.r += 0.01;
@ -735,16 +719,6 @@ if (this.mouseIsDown)
var mesh = intersect.mesh; 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 ( if (
mesh.name.indexOf('Tree - Medium') !== -1 || //tree medium mesh.name.indexOf('Tree - Medium') !== -1 || //tree medium
mesh.name.indexOf('Hamburger') !== -1 || //burger mesh.name.indexOf('Hamburger') !== -1 || //burger
@ -753,7 +727,8 @@ if (this.mouseIsDown)
mesh.name.indexOf('Bull') !== -1 || //bull mesh.name.indexOf('Bull') !== -1 || //bull
mesh.name.indexOf('Tree - Large') !== -1 || //tree large mesh.name.indexOf('Tree - Large') !== -1 || //tree large
mesh.name.indexOf('Santa') !== -1 || //santa 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) { if (mesh.materials[0].name.indexOf('Trees') === -1) {
@ -825,8 +800,7 @@ if (this.mouseIsDown)
); );
} }
else else {
{
this.kanisterTime += (data.delta * this.kanisterLeakTime); this.kanisterTime += (data.delta * this.kanisterLeakTime);
this.renderer.clearColor.r -= data.delta; this.renderer.clearColor.r -= data.delta;
@ -879,11 +853,10 @@ if (this.kanisterTime > this.kanisterLife) {
if (this.enemySpawnTime > this.enemySpawnInterval && this.running) { if (this.enemySpawnTime > this.enemySpawnInterval && this.running) {
this.enemySpawnTime = 0; this.enemySpawnTime = 0;
this.spawnEnemy(); this.spawnEnemy(false);
} }
this.enemies = this.enemies.reduce( this.enemies = this.enemies.reduce(
function (result, enemy) { function (result, enemy) {
/** /**
@ -968,5 +941,5 @@ this.enemies = this.enemies.reduce(
[] []
); );
return null; return null;//# sourceURL=beforeRender.js
//# sourceURL=beforeRender.js