Update: CC - Before Render - Moorcow (qemp4een6t.js) 694 bytes modified
parent
c75b1f6df2
commit
5e788b5bd6
411
qemp4een6t.js
411
qemp4een6t.js
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
if (!this.entityLoaded) {
|
if (!this.entityLoaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +13,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.PLAY_AUDIO,
|
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(
|
this.blastSubscription = GameLib.Event.Subscribe(
|
||||||
GameLib.Event.AUDIO_ENDED,
|
GameLib.Event.AUDIO_ENDED,
|
||||||
function(data) {
|
function (data) {
|
||||||
if (data.audio.name.indexOf('Blast') !== -1) {
|
if (data.audio.name.indexOf('Blast') !== -1) {
|
||||||
var play = GameLib.Utils.GetRandomIntInclusive(1,5);
|
var play = GameLib.Utils.GetRandomIntInclusive(1, 5);
|
||||||
if (play === 1) {
|
if (play === 1) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.PLAY_AUDIO,
|
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.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;
|
||||||
|
@ -86,7 +88,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
this.kanisterLeakTime = 0.1;
|
this.kanisterLeakTime = 0.1;
|
||||||
this.kanisterSpawnScore = 50;
|
this.kanisterSpawnScore = 50;
|
||||||
|
|
||||||
this.setNextKanisterSpawnScore = function() {
|
this.setNextKanisterSpawnScore = function () {
|
||||||
|
|
||||||
this.kanisterSpawnScore = this.score + 100;
|
this.kanisterSpawnScore = this.score + 100;
|
||||||
|
|
||||||
|
@ -135,14 +137,12 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
event : 'nextKanisterSpawnScoreUpdate',
|
event: 'nextKanisterSpawnScoreUpdate',
|
||||||
kanisterSpawnScore : this.kanisterSpawnScore
|
kanisterSpawnScore: this.kanisterSpawnScore
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.fuelFinished = false;
|
|
||||||
|
|
||||||
this.level = 1;
|
this.level = 1;
|
||||||
|
|
||||||
this.enemySpawnInterval = 5;
|
this.enemySpawnInterval = 5;
|
||||||
|
@ -152,19 +152,18 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
|
|
||||||
if (this.enemies instanceof Array && this.enemies.length !== 0) {
|
if (this.enemies instanceof Array && this.enemies.length !== 0) {
|
||||||
this.enemies.map(
|
this.enemies.map(
|
||||||
function(enemy) {
|
function (enemy) {
|
||||||
this.kill(enemy);
|
this.kill(enemy);
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scene.meshes.map(
|
this.scene.meshes.map(
|
||||||
function(mesh) {
|
function (mesh) {
|
||||||
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)
|
||||||
);
|
);
|
||||||
|
@ -185,12 +184,12 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GET_GRAPHICS_IMPLEMENTATION,
|
GameLib.Event.GET_GRAPHICS_IMPLEMENTATION,
|
||||||
null,
|
null,
|
||||||
function(graphics) {
|
function (graphics) {
|
||||||
this.graphics = graphics
|
this.graphics = graphics
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setLevelProperties = function() {
|
this.setLevelProperties = function () {
|
||||||
|
|
||||||
this.prevLevel = this.level;
|
this.prevLevel = this.level;
|
||||||
|
|
||||||
|
@ -212,26 +211,108 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
this.enemySpawnInterval = 1.5;
|
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.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
level : this.level,
|
level: this.level,
|
||||||
enemySpawnInterval : this.enemySpawnInterval,
|
enemySpawnInterval: this.enemySpawnInterval,
|
||||||
event : 'levelIncrease'
|
event: 'levelIncrease'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.spawnEnemy = function(kanister) {
|
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 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,77 +320,27 @@ 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(
|
||||||
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();
|
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 = {
|
var rotation = {
|
||||||
axis : axis,
|
axis: axis,
|
||||||
angle : angle
|
angle: angle
|
||||||
};
|
};
|
||||||
|
|
||||||
var enemy = {
|
var enemy = {
|
||||||
mesh : mesh
|
mesh: mesh
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -325,31 +356,31 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
if (enemyType === 1) {
|
if (enemyType === 1) {
|
||||||
position.x = -distance;
|
position.x = -distance;
|
||||||
life += 3 / speed;
|
life += 3 / speed;
|
||||||
velocity = {x:speed,y:0,z:0};
|
velocity = {x: speed, y: 0, z: 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enemyType === 2) {
|
if (enemyType === 2) {
|
||||||
position.x = distance;
|
position.x = distance;
|
||||||
life += 3 / speed;
|
life += 3 / speed;
|
||||||
velocity = {x:-speed,y:0,z:0};
|
velocity = {x: -speed, y: 0, z: 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enemyType === 3) {
|
if (enemyType === 3) {
|
||||||
position.x = -angledistance;
|
position.x = -angledistance;
|
||||||
position.z = -angledistance;
|
position.z = -angledistance;
|
||||||
velocity = {x:speed,y:0,z:speed};
|
velocity = {x: speed, y: 0, z: speed};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enemyType === 4) {
|
if (enemyType === 4) {
|
||||||
position.x = angledistance;
|
position.x = angledistance;
|
||||||
position.z = -angledistance;
|
position.z = -angledistance;
|
||||||
velocity = {x:-speed,y:0,z:speed};
|
velocity = {x: -speed, y: 0, z: speed};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enemyType === 5) {
|
if (enemyType === 5) {
|
||||||
position.x = 0;
|
position.x = 0;
|
||||||
position.z = -distance;
|
position.z = -distance;
|
||||||
velocity = {x:0,y:0,z:speed};
|
velocity = {x: 0, y: 0, z: speed};
|
||||||
}
|
}
|
||||||
|
|
||||||
enemy.mesh.position.x = position.x;
|
enemy.mesh.position.x = position.x;
|
||||||
|
@ -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,24 +426,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
this.enemies.push(enemy);
|
this.enemies.push(enemy);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spawnKanister = function() {
|
this.drawScore = function (enemy) {
|
||||||
|
|
||||||
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;
|
this.scoreMesh.materials[0].opacity = 1.0;
|
||||||
this.scoreMesh.materials[0].updateInstance('opacity');
|
this.scoreMesh.materials[0].updateInstance('opacity');
|
||||||
|
@ -427,26 +440,26 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
|
|
||||||
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
|
* Write text
|
||||||
*/
|
*/
|
||||||
context.fillStyle = '#e0b899';
|
context.fillStyle = '#e0b899';
|
||||||
context.font = '230pt BkBold';
|
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;
|
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';
|
||||||
|
|
||||||
|
@ -458,24 +471,21 @@ 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,
|
||||||
{
|
{
|
||||||
name : name
|
name: name
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.explode = function(mesh) {
|
this.explode = function (mesh) {
|
||||||
|
|
||||||
mesh.enemy.exploding = true;
|
mesh.enemy.exploding = true;
|
||||||
|
|
||||||
|
@ -502,20 +512,20 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
event : 'scoreUpdate',
|
event: 'scoreUpdate',
|
||||||
score : this.score
|
score: this.score
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.score > this.kanisterSpawnScore) {
|
if (this.score > this.kanisterSpawnScore) {
|
||||||
this.spawnKanister();
|
this.spawnEnemy(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
enemy : mesh.enemy,
|
enemy: mesh.enemy,
|
||||||
event : 'enemyExploded'
|
event: 'enemyExploded'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -523,7 +533,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
this.explodeMesh(mesh);
|
this.explodeMesh(mesh);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.burn = function(mesh) {
|
this.burn = function (mesh) {
|
||||||
|
|
||||||
console.log('burning enemy ' + mesh.name);
|
console.log('burning enemy ' + mesh.name);
|
||||||
|
|
||||||
|
@ -532,74 +542,63 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
enemy : mesh.enemy,
|
enemy: mesh.enemy,
|
||||||
event : 'enemyBurned'
|
event: 'enemyBurned'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
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,
|
||||||
{
|
{
|
||||||
name : 'Audio - Burning'
|
name: 'Audio - Burning'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.kill = function(enemy) {
|
this.kill = function (enemy) {
|
||||||
|
|
||||||
/**
|
var found = false;
|
||||||
* We only remove the things we cloned
|
|
||||||
*/
|
for (var i = 0; i < 5; i++) {
|
||||||
GameLib.Event.Emit(
|
if (this.meshes[enemy.meshType][i].mesh === enemy.mesh) {
|
||||||
GameLib.Event.REMOVE_COMPONENT,
|
found = true;
|
||||||
{
|
this.meshes[enemy.meshType][i].inUse = false;
|
||||||
component : enemy.mesh.materials[0]
|
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
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
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) {
|
||||||
|
|
||||||
if (mesh.burning) {
|
if (mesh.burning) {
|
||||||
/**
|
/**
|
||||||
|
@ -619,8 +618,8 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
event : 'gameRunning',
|
event: 'gameRunning',
|
||||||
message : 'we have enough trees burning now to start - the enemy will spawn now'
|
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.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
event : 'treeBurned',
|
event: 'treeBurned',
|
||||||
treesBurning : this.treesBurning,
|
treesBurning: this.treesBurning,
|
||||||
treesBurningToStart : this.treesBurningToStart
|
treesBurningToStart: this.treesBurningToStart
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -662,17 +661,12 @@ 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,
|
||||||
{
|
{
|
||||||
name : 'Audio - Burning'
|
name: 'Audio - Burning'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -681,7 +675,7 @@ if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_STARTED,
|
GameLib.Event.GAME_STARTED,
|
||||||
{
|
{
|
||||||
game : this
|
game: this
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -731,29 +715,20 @@ if (this.mouseIsDown)
|
||||||
|
|
||||||
var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes);
|
var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes);
|
||||||
intersects.map(
|
intersects.map(
|
||||||
function(intersect) {
|
function (intersect) {
|
||||||
|
|
||||||
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
|
||||||
mesh.name.indexOf('Star Cookie') !== -1 || //cookie
|
mesh.name.indexOf('Star Cookie') !== -1 || //cookie
|
||||||
mesh.name.indexOf('Parcel') !== -1 || //parcel
|
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('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;
|
||||||
|
@ -847,10 +821,10 @@ var used = this.kanisterTime / this.kanisterLife;
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
event : 'fuelUsed',
|
event: 'fuelUsed',
|
||||||
used : used,
|
used: used,
|
||||||
percentage : Math.round(used * 100) + '%',
|
percentage: Math.round(used * 100) + '%',
|
||||||
kanisters : this.kanisters
|
kanisters: this.kanisters
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -862,8 +836,8 @@ if (this.kanisterTime > this.kanisterLife) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
event : 'kanisterCountUpdate',
|
event: 'kanisterCountUpdate',
|
||||||
kanisters : this.kanisters
|
kanisters: this.kanisters
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -871,7 +845,7 @@ if (this.kanisterTime > this.kanisterLife) {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_OVER,
|
GameLib.Event.GAME_OVER,
|
||||||
{
|
{
|
||||||
game : this
|
game: this
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -879,12 +853,11 @@ 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) {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update enemy position and rotation
|
* Update enemy position and rotation
|
||||||
|
@ -906,8 +879,8 @@ this.enemies = this.enemies.reduce(
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.GAME_DATA,
|
GameLib.Event.GAME_DATA,
|
||||||
{
|
{
|
||||||
event : 'enemyLifetimeReached',
|
event: 'enemyLifetimeReached',
|
||||||
enemy : enemy
|
enemy: enemy
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -968,5 +941,5 @@ this.enemies = this.enemies.reduce(
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
return null;//# sourceURL=beforeRender.js
|
||||||
//# sourceURL=beforeRender.js
|
|
||||||
|
|
Loading…
Reference in New Issue