2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
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();
|
|
|
|
}
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
);
|
2017-11-27 11:18:10 +01:00
|
|
|
}
|
2017-11-27 10:33:54 +01:00
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
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.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;
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
this.minimumRendererRed = 0.1;
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
this.toBlack = new THREE.Color(
|
|
|
|
data.delta * 3,
|
|
|
|
data.delta * 3,
|
|
|
|
data.delta * 3
|
|
|
|
);
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
this.toRed = new THREE.Color(
|
|
|
|
data.delta * 1.2,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
);
|
2017-11-27 10:33:54 +01:00
|
|
|
|
|
|
|
this.treesBurning = 0;
|
|
|
|
this.treesBurningToStart = GameLib.Utils.GetRandomIntInclusive(1, 3);
|
|
|
|
|
|
|
|
this.running = false;
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
this.totalTime = 0;
|
|
|
|
|
|
|
|
this.kanisters = 3;
|
|
|
|
this.kanisterTime = 0;
|
|
|
|
this.kanisterLife = 16.344;
|
|
|
|
this.kanisterLeakTime = 0.1;
|
|
|
|
this.kanisterSpawnScore = 50;
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
this.setNextKanisterSpawnScore = function() {
|
|
|
|
|
|
|
|
this.kanisterSpawnScore = this.score + 100;
|
|
|
|
|
|
|
|
if (this.score > 200) {
|
|
|
|
this.kanisterSpawnScore = this.score + 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.score > 500) {
|
|
|
|
this.kanisterSpawnScore = this.score + 300;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.score > 800) {
|
|
|
|
this.kanisterSpawnScore = this.score + 400;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.score > 1100) {
|
|
|
|
this.kanisterSpawnScore = this.score + 500;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.score > 1400) {
|
|
|
|
this.kanisterSpawnScore = this.score + 600;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.score > 1800) {
|
|
|
|
this.kanisterSpawnScore = this.score + 700;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.score > 2500) {
|
|
|
|
this.kanisterSpawnScore = this.score + 800;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.score > 3200) {
|
|
|
|
this.kanisterSpawnScore = this.score + 900;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.score > 4000) {
|
|
|
|
this.kanisterSpawnScore = this.score + 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.score > 5000) {
|
|
|
|
this.kanisterSpawnScore = this.score + 1100;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('next kanister spawn score: ' + this.kanisterSpawnScore);
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'nextKanisterSpawnScoreUpdate',
|
|
|
|
kanisterSpawnScore : this.kanisterSpawnScore
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.fuelFinished = false;
|
|
|
|
|
|
|
|
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;
|
2017-11-27 11:18:10 +01:00
|
|
|
mesh.burnLife = 1;
|
2017-11-27 10:33:54 +01:00
|
|
|
mesh.burningTreeParticleEngine.remove();
|
|
|
|
mesh.burningTreeParticleEngine = null;
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
this.enemies = [];
|
|
|
|
|
|
|
|
this.scores = [];
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
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.enemiesSpawned / 10) + 1;
|
|
|
|
|
|
|
|
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.spawnEnemy = function(kanister) {
|
|
|
|
|
|
|
|
var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5);
|
|
|
|
var meshType = GameLib.Utils.GetRandomIntInclusive(1, 5);
|
|
|
|
|
|
|
|
if (kanister) {
|
|
|
|
meshType = 6;
|
|
|
|
} else {
|
|
|
|
this.enemiesSpawned++;
|
|
|
|
this.setLevelProperties();
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
mesh.visible = true;
|
|
|
|
mesh.updateInstance('visible');
|
|
|
|
|
|
|
|
mesh.burnLife = 1;
|
|
|
|
mesh.explodeLife = 1;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
/**
|
|
|
|
* Link the enemy to the mesh
|
|
|
|
*/
|
|
|
|
mesh.enemy = enemy;
|
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
var distance = 100;
|
|
|
|
var angledistance = distance * Math.sin(Math.PI / 4);
|
|
|
|
|
|
|
|
var life = 5 / speed;
|
|
|
|
|
|
|
|
if (enemyType === 1) {
|
|
|
|
position.x = -distance;
|
|
|
|
life += 3 / speed;
|
|
|
|
velocity = {x:speed,y:0,z:0};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemyType === 2) {
|
|
|
|
position.x = distance;
|
|
|
|
life += 3 / 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 === 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};
|
|
|
|
}
|
|
|
|
|
|
|
|
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.velocity = velocity;
|
|
|
|
enemy.rotation = rotation;
|
|
|
|
|
|
|
|
enemy.lifeTime = 0;
|
|
|
|
enemy.life = life;
|
|
|
|
|
|
|
|
enemy.exploding = false;
|
|
|
|
enemy.burning = false;
|
2017-11-27 11:31:58 +01:00
|
|
|
enemy.burnLife = 1.5;
|
2017-11-27 10:33:54 +01:00
|
|
|
enemy.burnTime = 0;
|
|
|
|
enemy.explodingLife = 2;
|
|
|
|
enemy.meshType = meshType;
|
|
|
|
enemy.score = score;
|
|
|
|
enemy.isKanister = false;
|
|
|
|
|
|
|
|
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.spawnKanister = function() {
|
|
|
|
|
|
|
|
console.log('spawning kanister');
|
|
|
|
|
|
|
|
this.setNextKanisterSpawnScore();
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'kanisterCountUpdate',
|
|
|
|
kanisters : this.kanisters
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.spawnEnemy(true);
|
|
|
|
};
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
this.drawScore = function(enemy) {
|
|
|
|
|
|
|
|
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.instance.quaternion.copy(this.camera.instance.quaternion);
|
|
|
|
|
|
|
|
var context = this.scoreCanvas.instance.getContext('2d');
|
|
|
|
|
|
|
|
context.textBaseline = "middle";
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
this.scoreTexture.instance.needsUpdate = true;
|
|
|
|
|
|
|
|
}.bind(this)
|
2017-11-27 10:33:54 +01:00
|
|
|
|
|
|
|
this.explodeMesh = function(mesh) {
|
|
|
|
|
|
|
|
mesh.visible = false;
|
|
|
|
|
|
|
|
mesh.updateInstance('visible');
|
|
|
|
|
|
|
|
var sound = GameLib.Utils.GetRandomIntInclusive(1,3);
|
|
|
|
|
|
|
|
var name = 'Audio - Blast 1';
|
|
|
|
|
|
|
|
if (sound === 2) {
|
|
|
|
name = 'Audio - Blast 2';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sound === 3) {
|
|
|
|
name = 'Audio - Blast 3';
|
|
|
|
}
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
var explodeParticleEngine = this.explodeParticleEngine.clone();
|
2017-11-27 11:47:10 +01:00
|
|
|
explodeParticleEngine.position.x = mesh.position.x;
|
|
|
|
explodeParticleEngine.position.y = mesh.position.y;
|
|
|
|
explodeParticleEngine.position.z = mesh.position.z;
|
2017-11-27 11:18:10 +01:00
|
|
|
explodeParticleEngine.updateInstance('position');
|
|
|
|
explodeParticleEngine.enabled = true;
|
|
|
|
mesh.explodeParticleEngine = explodeParticleEngine;
|
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.PLAY_AUDIO,
|
|
|
|
{
|
|
|
|
name : name
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
this.explode = function(mesh) {
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
mesh.enemy.exploding = true;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
if (mesh.enemy.isKanister) {
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
console.log('exploding kanister');
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
this.kanisters += 1;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
if (this.kanisters > 9) {
|
|
|
|
this.kanisters = 9;
|
|
|
|
}
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
} else {
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
console.log('exploding enemy');
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
this.score += mesh.enemy.score;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
this.drawScore(mesh.enemy);
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
console.log('score : ' + this.score);
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'scoreUpdate',
|
|
|
|
score : this.score
|
|
|
|
}
|
|
|
|
);
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
if (this.score > this.kanisterSpawnScore) {
|
|
|
|
this.spawnKanister();
|
|
|
|
}
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
enemy : mesh.enemy,
|
|
|
|
event : 'enemyExploded'
|
2017-11-27 10:33:54 +01:00
|
|
|
}
|
2017-11-27 11:18:10 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.explodeMesh(mesh);
|
2017-11-27 10:33:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.burn = function(mesh) {
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
console.log('burning enemy ' + mesh.name);
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
mesh.enemy.burning = true;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
enemy : mesh.enemy,
|
|
|
|
event : 'enemyBurned'
|
|
|
|
}
|
|
|
|
);
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
var smokeParticleEngine = this.smokeParticleEngine.clone();
|
|
|
|
smokeParticleEngine.position = mesh.position.clone();
|
|
|
|
smokeParticleEngine.updateInstance('position');
|
|
|
|
smokeParticleEngine.enabled = true;
|
|
|
|
mesh.smokeParticleEngine = smokeParticleEngine;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
var fireParticleEngine = this.fireParticleEngine.clone();
|
|
|
|
fireParticleEngine.position = mesh.position.clone();
|
|
|
|
fireParticleEngine.updateInstance('position');
|
|
|
|
fireParticleEngine.enabled = true;
|
|
|
|
mesh.fireParticleEngine = fireParticleEngine;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.PLAY_AUDIO,
|
|
|
|
{
|
|
|
|
name : 'Audio - Burning'
|
|
|
|
}
|
2017-11-27 10:33:54 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.kill = function(enemy) {
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
/**
|
|
|
|
* We only remove the things we cloned
|
|
|
|
*/
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.REMOVE_COMPONENT,
|
|
|
|
{
|
|
|
|
component : enemy.mesh.materials[0]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
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 (enemy.mesh.smokeParticleEngine) {
|
|
|
|
enemy.mesh.smokeParticleEngine.remove();
|
|
|
|
enemy.mesh.smokeParticleEngine = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemy.mesh.fireParticleEngine) {
|
|
|
|
enemy.mesh.fireParticleEngine.remove();
|
|
|
|
enemy.mesh.fireParticleEngine = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemy.mesh.explodeParticleEngine) {
|
|
|
|
enemy.mesh.explodeParticleEngine.remove();
|
|
|
|
enemy.mesh.explodeParticleEngine = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
this.burnTree = function(mesh) {
|
|
|
|
|
|
|
|
if (mesh.burning) {
|
|
|
|
/**
|
|
|
|
* Do nothing, this tree is burning
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mesh.burning = true;
|
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'treeBurned',
|
|
|
|
treesBurning : this.treesBurning,
|
|
|
|
treesBurningToStart : this.treesBurningToStart
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.minimumRendererRed += 0.01;
|
|
|
|
|
|
|
|
this.fog.density -= 0.00025;
|
|
|
|
if (this.fog.density < 0.0055) {
|
|
|
|
this.fog.density = 0.0055;
|
|
|
|
}
|
|
|
|
this.fog.updateInstance('density');
|
|
|
|
|
|
|
|
if (mesh.position.x < 0) {
|
2017-11-27 11:18:10 +01:00
|
|
|
this.leftLight.intensity += data.delta * 2.5;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
|
|
|
if (this.leftLight.intensity >= 1) {
|
|
|
|
this.leftLight.intensity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.leftLight.updateInstance('intensity');
|
|
|
|
|
|
|
|
} else {
|
2017-11-27 11:18:10 +01:00
|
|
|
this.rightLight.intensity += data.delta * 2.5;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
|
|
|
if (this.rightLight.intensity >= 1) {
|
|
|
|
this.rightLight.intensity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.rightLight.updateInstance('intensity');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2017-11-27 11:18:10 +01:00
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.PLAY_AUDIO,
|
|
|
|
{
|
|
|
|
name : 'Audio - Burning'
|
|
|
|
}
|
|
|
|
);
|
2017-11-27 10:33:54 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_STARTED,
|
|
|
|
{
|
|
|
|
game : this
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.totalTime += data.delta;
|
|
|
|
this.enemySpawnTime += data.delta;
|
|
|
|
|
|
|
|
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.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)
|
2017-11-27 11:18:10 +01:00
|
|
|
{
|
2017-11-27 10:33:54 +01:00
|
|
|
this.kanisterTime += data.delta;
|
|
|
|
|
|
|
|
this.renderer.clearColor.r += 0.01;
|
|
|
|
if (this.renderer.clearColor.r > 0.45) {
|
|
|
|
this.renderer.clearColor.r = 0.45;
|
|
|
|
}
|
|
|
|
this.renderer.updateInstance('clearColor');
|
|
|
|
|
|
|
|
this.throwerLight.intensity += 0.05;
|
|
|
|
if (this.throwerLight.intensity > 2) {
|
|
|
|
this.throwerLight.intensity = 2;
|
|
|
|
}
|
|
|
|
this.throwerLight.updateInstance('intensity');
|
|
|
|
|
|
|
|
var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes);
|
|
|
|
intersects.map(
|
|
|
|
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('Tree - Large') !== -1 || //tree large
|
|
|
|
mesh.name.indexOf('Santa') !== -1 || //santa
|
|
|
|
mesh.name.indexOf('Tree - Small') !== -1 //tree small
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (mesh.materials[0].name.indexOf('Trees') === -1) {
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
if (!mesh.enemy.burning) {
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
mesh.burnLife -= data.delta * 2.5;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
if (mesh.burnLife < 0) {
|
|
|
|
mesh.burnLife = 0;
|
|
|
|
this.burn(mesh);
|
|
|
|
}
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
mesh.instance.material.color.setRGB(
|
|
|
|
mesh.burnLife,
|
|
|
|
mesh.burnLife,
|
|
|
|
mesh.burnLife
|
|
|
|
);
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
} else {
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
if (!mesh.enemy.exploding) {
|
|
|
|
mesh.explodeLife -= data.delta * 2.5;
|
|
|
|
if (mesh.explodeLife < 0) {
|
|
|
|
mesh.explodeLife = 0;
|
2017-11-27 10:33:54 +01:00
|
|
|
this.explode(mesh);
|
|
|
|
}
|
2017-11-27 11:18:10 +01:00
|
|
|
|
|
|
|
if (mesh.instance.material.emissive) {
|
|
|
|
mesh.instance.material.emissive.setRGB(
|
|
|
|
1 - mesh.explodeLife,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
2017-11-27 10:33:54 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
} else {
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
/**
|
|
|
|
* This happens to trees
|
|
|
|
*/
|
2017-11-27 11:18:10 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(mesh.burnLife)) {
|
|
|
|
mesh.burnLife = 1;
|
2017-11-27 11:27:47 +01:00
|
|
|
mesh.burning = false;
|
2017-11-27 10:33:54 +01:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
if (!mesh.burning) {
|
|
|
|
|
|
|
|
mesh.burnLife -= data.delta * 2;
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
if (mesh.burnLife <= 0) {
|
2017-11-27 11:27:47 +01:00
|
|
|
mesh.burnLife = 0;
|
2017-11-27 11:18:10 +01:00
|
|
|
this.burnTree(mesh);
|
2017-11-27 11:27:47 +01:00
|
|
|
}
|
2017-11-27 11:18:10 +01:00
|
|
|
|
2017-11-27 11:27:47 +01:00
|
|
|
if (mesh.instance.material.emissive) {
|
|
|
|
mesh.instance.material.emissive.setRGB(
|
|
|
|
1 - mesh.burnLife,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
);
|
2017-11-27 10:33:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.kanisterTime += (data.delta * this.kanisterLeakTime);
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
this.renderer.clearColor.r -= data.delta;
|
2017-11-27 10:33:54 +01:00
|
|
|
if (this.renderer.clearColor.r < this.minimumRendererRed) {
|
|
|
|
this.renderer.clearColor.r = this.minimumRendererRed;
|
|
|
|
}
|
|
|
|
this.renderer.updateInstance('clearColor');
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
this.throwerLight.intensity -= data.delta * 3;
|
2017-11-27 10:33:54 +01:00
|
|
|
if (this.throwerLight.intensity < 0) {
|
|
|
|
this.throwerLight.intensity = 0;
|
|
|
|
}
|
|
|
|
this.throwerLight.updateInstance('intensity');
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (this.kanisterTime > this.kanisterLife) {
|
|
|
|
|
|
|
|
this.kanisterTime = 0;
|
|
|
|
this.kanisters -= 1;
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'kanisterCountUpdate',
|
|
|
|
kanisters : this.kanisters
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (this.kanisters < 0) {
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_OVER,
|
|
|
|
{
|
|
|
|
game : this
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.enemySpawnTime > this.enemySpawnInterval && this.running) {
|
|
|
|
this.enemySpawnTime = 0;
|
|
|
|
this.spawnEnemy();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.enemies = this.enemies.reduce(
|
|
|
|
|
2017-11-27 11:47:10 +01:00
|
|
|
function(result, enemy) {
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:47:10 +01:00
|
|
|
/**
|
|
|
|
* Update enemy position and rotation
|
|
|
|
*/
|
2017-11-27 11:21:32 +01:00
|
|
|
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;
|
2017-11-27 10:33:54 +01:00
|
|
|
enemy.mesh.updateInstance('position');
|
|
|
|
|
2017-11-27 11:18:10 +01:00
|
|
|
enemy.mesh.quaternion.angle += enemy.rotation.angle * data.delta;
|
2017-11-27 10:33:54 +01:00
|
|
|
enemy.mesh.updateInstance('quaternion');
|
|
|
|
|
2017-11-27 11:47:10 +01:00
|
|
|
/**
|
|
|
|
* Update its lifetime
|
|
|
|
*/
|
2017-11-27 10:33:54 +01:00
|
|
|
enemy.lifeTime += data.delta;
|
|
|
|
if (enemy.lifeTime > enemy.life) {
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'enemyLifetimeReached',
|
|
|
|
enemy : enemy
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We only remove the things we cloned
|
|
|
|
*/
|
|
|
|
this.kill(enemy);
|
|
|
|
return result;
|
2017-11-27 11:47:10 +01:00
|
|
|
}
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:47:10 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:47:10 +01:00
|
|
|
if (enemy.burning) {
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:47:10 +01:00
|
|
|
if (!enemy.exploding) {
|
2017-11-27 10:33:54 +01:00
|
|
|
enemy.burnTime += data.delta;
|
|
|
|
if (enemy.burnTime > enemy.burnLife) {
|
2017-11-27 11:30:35 +01:00
|
|
|
this.explode(enemy.mesh);
|
2017-11-27 10:33:54 +01:00
|
|
|
}
|
2017-11-27 11:47:10 +01:00
|
|
|
}
|
2017-11-27 10:33:54 +01:00
|
|
|
|
2017-11-27 11:47:10 +01:00
|
|
|
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');
|
2017-11-27 10:33:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result.push(enemy);
|
|
|
|
return result;
|
|
|
|
}
|
2017-11-27 11:50:52 +01:00
|
|
|
|
|
|
|
result.push(enemy);
|
2017-11-27 11:47:10 +01:00
|
|
|
return result;
|
|
|
|
|
2017-11-27 10:33:54 +01:00
|
|
|
}.bind(this),
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
return null;
|
2017-11-27 11:18:10 +01:00
|
|
|
//# sourceURL=beforeRender.js
|