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) {
return;
}
@ -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;
@ -141,8 +143,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
);
};
this.fuelFinished = false;
this.level = 1;
this.enemySpawnInterval = 5;
@ -163,8 +163,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
if (mesh.burningTreeParticleEngine) {
mesh.burning = false;
mesh.burnLife = 1;
mesh.burningTreeParticleEngine.remove();
mesh.burningTreeParticleEngine = null;
mesh.burningTreeParticleEngine.enabled = false;
}
}.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) {
var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5);
var meshType = 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,56 +320,6 @@ 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(
@ -382,7 +413,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
if (kanister) {
enemy.isKanister = true;
} else {
GameLib.Event.Emit(
GameLib.Event.GAME_DATA,
{
@ -396,23 +426,6 @@ 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.scoreMesh.materials[0].opacity = 1.0;
@ -458,13 +471,11 @@ 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,
@ -472,7 +483,6 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
name: name
}
);
};
this.explode = function (mesh) {
@ -508,7 +518,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
);
if (this.score > this.kanisterSpawnScore) {
this.spawnKanister();
this.spawnEnemy(true);
}
GameLib.Event.Emit(
@ -537,17 +547,17 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
}
);
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,
@ -559,45 +569,34 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
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;
GameLib.Event.Emit(
GameLib.Event.REMOVE_COMPONENT,
{
component : enemy.mesh
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');
}
}
);
/**
* 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) {
@ -662,12 +661,7 @@ 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,
@ -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);
}
}
}.bind(this)
);
if (this.mouseIsDown)
{
if (this.mouseIsDown) {
this.kanisterTime += data.delta;
this.renderer.clearColor.r += 0.01;
@ -735,16 +719,6 @@ if (this.mouseIsDown)
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
@ -753,7 +727,8 @@ if (this.mouseIsDown)
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;
@ -879,11 +853,10 @@ 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) {
/**
@ -968,5 +941,5 @@ this.enemies = this.enemies.reduce(
[]
);
return null;
//# sourceURL=beforeRender.js
return null;//# sourceURL=beforeRender.js