2017-11-24 13:15:11 +01:00
|
|
|
if (!this.entityLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
|
|
|
|
|
|
|
this.initialized = true;
|
|
|
|
|
|
|
|
GameLib.Event.Emit(GameLib.Event.STOP_ALL_AUDIO);
|
2017-11-24 15:25:34 +01:00
|
|
|
|
2017-11-24 15:21:22 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.PLAY_AUDIO,
|
|
|
|
{
|
|
|
|
name : 'Audio - Xmas'
|
|
|
|
}
|
|
|
|
);
|
2017-11-24 15:25:34 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
this.fog = this.entityLoaded.fog;
|
|
|
|
this.bull = this.entityLoaded.bull;
|
|
|
|
this.star = this.entityLoaded.star;
|
|
|
|
this.burger = this.entityLoaded.burger;
|
|
|
|
this.parcel = this.entityLoaded.parcel;
|
|
|
|
this.santa = this.entityLoaded.santa;
|
|
|
|
this.renderer = this.entityLoaded.renderer;
|
|
|
|
this.raycaster = this.entityLoaded.raycaster;
|
|
|
|
this.kanister = this.entityLoaded.kanister;
|
|
|
|
this.scene = this.entityLoaded.scene;
|
|
|
|
this.leftLight = this.entityLoaded.leftLight;
|
|
|
|
this.rightLight = this.entityLoaded.rightLight;
|
|
|
|
this.throwerLight = this.entityLoaded.throwerLight;
|
|
|
|
this.smokeParticleEngine = this.entityLoaded.smokeParticleEngine;
|
|
|
|
this.fireParticleEngine = this.entityLoaded.fireParticleEngine;
|
|
|
|
this.burningTreeParticleEngine = this.entityLoaded.burningTreeParticleEngine;
|
|
|
|
this.explodeParticleEngine = this.entityLoaded.explodeParticleEngine;
|
|
|
|
|
|
|
|
this.minimumRendererRed = 0.1;
|
|
|
|
|
|
|
|
this.toBlack = new THREE.Color(0.05, 0.05, 0.05);
|
|
|
|
this.toRed = new THREE.Color(0.02, 0, 0);
|
|
|
|
|
|
|
|
this.bull.instance.visible = false;
|
|
|
|
this.star.instance.visible = false;
|
|
|
|
this.burger.instance.visible = false;
|
|
|
|
this.parcel.instance.visible = false;
|
|
|
|
this.santa.instance.visible = false;
|
|
|
|
|
|
|
|
this.treesBurning = 0;
|
|
|
|
this.treesBurningToStart = GameLib.Utils.GetRandomIntInclusive(1, 3);
|
|
|
|
|
|
|
|
this.running = false;
|
|
|
|
|
|
|
|
/**
|
2017-11-22 10:24:51 +01:00
|
|
|
* This component is initializing - set the total time to 0
|
|
|
|
*/
|
2017-11-24 13:15:11 +01:00
|
|
|
this.totalTime = 0;
|
|
|
|
|
|
|
|
this.kanisters = 4;
|
2017-11-24 15:25:34 +01:00
|
|
|
this.kanisterTime = 0;
|
2017-11-24 13:15:11 +01:00
|
|
|
this.kanisterLife = 16.344;
|
2017-11-24 15:44:04 +01:00
|
|
|
this.kanisterLeakTime = 0.1;
|
2017-11-24 14:42:52 +01:00
|
|
|
this.kanisterSpawnScore = 50;
|
|
|
|
|
|
|
|
this.setNextKanisterSpawnScore = function() {
|
|
|
|
|
2017-11-24 14:51:13 +01:00
|
|
|
this.kanisterSpawnScore = this.score + 100;
|
2017-11-24 15:25:34 +01:00
|
|
|
|
2017-11-24 14:49:52 +01:00
|
|
|
if (this.score > 200) {
|
|
|
|
this.kanisterSpawnScore = this.score + 200;
|
2017-11-24 14:42:52 +01:00
|
|
|
}
|
|
|
|
|
2017-11-24 14:49:52 +01:00
|
|
|
if (this.score > 500) {
|
|
|
|
this.kanisterSpawnScore = this.score + 300;
|
2017-11-24 14:42:52 +01:00
|
|
|
}
|
|
|
|
|
2017-11-24 14:49:52 +01:00
|
|
|
if (this.score > 800) {
|
|
|
|
this.kanisterSpawnScore = this.score + 400;
|
2017-11-24 14:42:52 +01:00
|
|
|
}
|
|
|
|
|
2017-11-24 14:49:52 +01:00
|
|
|
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;
|
2017-11-24 14:42:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log('next kanister spawn score: ' + this.kanisterSpawnScore);
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'nextKanisterSpawnScoreUpdate',
|
|
|
|
kanisterSpawnScore : this.kanisterSpawnScore
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
2017-11-24 13:15:11 +01:00
|
|
|
|
|
|
|
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);
|
2017-11-22 10:24:51 +01:00
|
|
|
}.bind(this)
|
|
|
|
)
|
2017-11-24 13:15:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.scene.meshes.map(
|
|
|
|
function(mesh) {
|
|
|
|
if (mesh.burningTreeParticleEngine) {
|
|
|
|
mesh.burning = false;
|
|
|
|
mesh.life = 1.2;
|
|
|
|
mesh.burningTreeParticleEngine.remove();
|
|
|
|
mesh.burningTreeParticleEngine = null;
|
2017-11-22 10:24:51 +01:00
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
this.enemies = [];
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
if (this.level === 1) {
|
|
|
|
this.enemySpawnInterval = 4;
|
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
if (this.level === 2) {
|
|
|
|
this.enemySpawnInterval = 3;
|
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
if (this.level === 3) {
|
|
|
|
this.enemySpawnInterval = 2;
|
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
if (this.level > 3) {
|
|
|
|
this.enemySpawnInterval = 1.5;
|
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
console.log('level : ' + this.level +', spawn interval : ' + this.enemySpawnInterval);
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
level : this.level,
|
|
|
|
enemySpawnInterval : this.enemySpawnInterval,
|
|
|
|
event : 'levelIncrease'
|
|
|
|
}
|
|
|
|
);
|
2017-11-24 13:15:11 +01:00
|
|
|
};
|
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
this.spawnKanister = function() {
|
2017-11-24 15:39:14 +01:00
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
console.log('spawning kanister');
|
2017-11-24 15:39:14 +01:00
|
|
|
|
|
|
|
this.setNextKanisterSpawnScore();
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'kanisterCountUpdate',
|
2017-11-24 15:44:04 +01:00
|
|
|
kanisters : this.kanisters
|
2017-11-24 15:39:14 +01:00
|
|
|
}
|
|
|
|
);
|
2017-11-24 14:42:52 +01:00
|
|
|
};
|
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
this.spawnEnemy = function() {
|
|
|
|
|
|
|
|
this.enemiesSpawned++;
|
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
this.setLevelProperties();
|
2017-11-24 13:15:11 +01:00
|
|
|
|
|
|
|
var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5);
|
|
|
|
var meshType = GameLib.Utils.GetRandomIntInclusive(1, 5);
|
|
|
|
|
|
|
|
var y = GameLib.Utils.GetRandomIntInclusive(2, 10);
|
|
|
|
|
|
|
|
var speed = 1;
|
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
var score = 10;
|
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var material = null;
|
|
|
|
|
|
|
|
var mesh = null;
|
|
|
|
if (meshType === 1) {
|
|
|
|
mesh = this.bull.clone();
|
|
|
|
material = this.bull.materials[0].clone();
|
|
|
|
speed = 0.2;
|
|
|
|
} else if (meshType === 2) {
|
|
|
|
mesh = this.star.clone();
|
2017-11-24 14:00:24 +01:00
|
|
|
score = 20;
|
2017-11-24 13:15:11 +01:00
|
|
|
material = this.star.materials[0].clone();
|
|
|
|
speed = 0.3;
|
|
|
|
} else if (meshType === 3) {
|
|
|
|
mesh = this.burger.clone();
|
2017-11-24 14:00:24 +01:00
|
|
|
score = 50;
|
2017-11-24 13:15:11 +01:00
|
|
|
material = this.burger.materials[0].clone();
|
|
|
|
speed = 0.4;
|
|
|
|
} else if (meshType === 4) {
|
|
|
|
mesh = this.parcel.clone();
|
2017-11-24 14:00:24 +01:00
|
|
|
score = 75;
|
2017-11-24 13:15:11 +01:00
|
|
|
material = this.parcel.materials[0].clone();
|
|
|
|
speed = 0.5;
|
|
|
|
} else if (meshType === 5) {
|
|
|
|
mesh = this.santa.clone();
|
2017-11-24 14:00:24 +01:00
|
|
|
score = 100;
|
2017-11-24 13:15:11 +01:00
|
|
|
material = this.santa.materials[0].clone();
|
|
|
|
speed = 0.6;
|
|
|
|
} else {
|
|
|
|
console.log('unknown mesh type : ' + meshType);
|
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
mesh.materials = [material];
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
mesh.updateInstance();
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
mesh.instance.visible = true;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var velocity = null;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
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
|
|
|
|
);
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
axis = axis.normalize();
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var angle = GameLib.Utils.GetRandomIntInclusive(1,100) * 0.001;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var position = {x : 0, y: y, z :0};
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var rotation = {
|
|
|
|
axis : axis,
|
|
|
|
angle : angle
|
|
|
|
};
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var enemy = {
|
|
|
|
mesh : mesh
|
|
|
|
};
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var distance = 100;
|
|
|
|
var angledistance = distance * Math.sin(Math.PI / 4);
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var life = 2.5 / speed;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (enemyType === 1) {
|
|
|
|
position.x = -distance;
|
|
|
|
life += 1.5 / speed;
|
|
|
|
velocity = {x:speed,y:0,z:0};
|
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (enemyType === 2) {
|
|
|
|
position.x = distance;
|
|
|
|
life += 1.5 / speed;
|
|
|
|
velocity = {x:-speed,y:0,z:0};
|
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (enemyType === 3) {
|
|
|
|
position.x = -angledistance;
|
|
|
|
position.z = -angledistance;
|
|
|
|
velocity = {x:speed,y:0,z:speed};
|
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (enemyType === 4) {
|
|
|
|
position.x = angledistance;
|
|
|
|
position.z = -angledistance;
|
|
|
|
velocity = {x:-speed,y:0,z:speed};
|
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (enemyType === 5) {
|
|
|
|
position.x = 0;
|
|
|
|
position.z = -distance;
|
|
|
|
velocity = {x:0,y:0,z:speed};
|
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
enemy.mesh.position.x = position.x;
|
|
|
|
enemy.mesh.position.y = position.y;
|
|
|
|
enemy.mesh.position.z = position.z;
|
|
|
|
enemy.mesh.updateInstancePosition();
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
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.updateInstanceRotation();
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
enemy.velocity = velocity;
|
|
|
|
enemy.rotation = rotation;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
enemy.lifeTime = 0;
|
|
|
|
enemy.life = life;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
enemy.exploding = false;
|
|
|
|
enemy.burning = false;
|
|
|
|
enemy.burnLife = 3;
|
|
|
|
enemy.burnTime = 0;
|
|
|
|
enemy.explodingLife = 2;
|
|
|
|
enemy.meshType = meshType;
|
2017-11-24 14:00:24 +01:00
|
|
|
enemy.score = score;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
enemiesSpawned : this.enemiesSpawned,
|
|
|
|
enemy : enemy,
|
|
|
|
event : 'enemySpawned'
|
|
|
|
}
|
|
|
|
);
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
this.enemies.push(enemy);
|
|
|
|
};
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
this.explodeMesh = function(mesh) {
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
mesh.visible = false;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
mesh.updateInstance('visible');
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var sound = GameLib.Utils.GetRandomIntInclusive(1,3);
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
var name = 'Audio - Blast 1';
|
|
|
|
|
|
|
|
if (sound === 2) {
|
|
|
|
name = 'Audio - Blast 2';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sound === 3) {
|
|
|
|
name = 'Audio - Blast 3';
|
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
this.blastSubscription = GameLib.Event.Subscribe(
|
|
|
|
GameLib.Event.AUDIO_ENDED,
|
|
|
|
function(data) {
|
|
|
|
|
|
|
|
if (data.audio.name === name) {
|
|
|
|
|
|
|
|
if (this.blastSubscription) {
|
|
|
|
|
|
|
|
this.blastSubscription.remove();
|
|
|
|
|
|
|
|
this.blastSubscription = null;
|
|
|
|
|
|
|
|
var play = GameLib.Utils.GetRandomIntInclusive(1,3);
|
|
|
|
|
|
|
|
if (play === 1) {
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.PLAY_AUDIO,
|
|
|
|
{
|
|
|
|
name : 'Audio - Ho ho ho'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.PLAY_AUDIO,
|
|
|
|
{
|
|
|
|
name : name
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
var explodeParticleEngine = this.explodeParticleEngine.clone();
|
|
|
|
explodeParticleEngine.position = mesh.position.clone();
|
|
|
|
explodeParticleEngine.updateInstance('position');
|
|
|
|
explodeParticleEngine.enabled = true;
|
|
|
|
mesh.explodeParticleEngine = explodeParticleEngine;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
this.explode = function(mesh) {
|
|
|
|
|
|
|
|
this.enemies.map(
|
|
|
|
function(enemy) {
|
|
|
|
if (enemy.mesh === mesh && !enemy.exploding) {
|
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
enemy.exploding = true;
|
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
console.log('exploding enemy');
|
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
this.score += enemy.score;
|
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
console.log('score : ' + this.score);
|
|
|
|
|
2017-11-24 14:00:24 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'scoreUpdate',
|
|
|
|
score : this.score
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
if (this.score > this.kanisterSpawnScore) {
|
|
|
|
this.spawnKanister();
|
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
enemy : enemy,
|
|
|
|
event : 'enemyExploded'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.explodeMesh(mesh);
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.explodeKanister = function() {
|
2017-11-24 14:42:52 +01:00
|
|
|
this.kanisters += 1;
|
2017-11-24 15:25:34 +01:00
|
|
|
this.kanisterTime = 0;
|
2017-11-24 14:42:52 +01:00
|
|
|
// this.fuelFinished = false;
|
2017-11-24 13:15:11 +01:00
|
|
|
this.explodeMesh(this.kanister);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.burn = function(mesh) {
|
|
|
|
|
|
|
|
this.enemies.map(
|
|
|
|
function(enemy) {
|
|
|
|
if (enemy.mesh === mesh && !enemy.burning) {
|
2017-11-24 14:00:24 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
console.log('burning enemy ' + mesh.name);
|
|
|
|
enemy.burning = true;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 12:59:37 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
2017-11-24 13:15:11 +01:00
|
|
|
enemy : enemy,
|
|
|
|
event : 'enemyBurned'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
var smokeParticleEngine = this.smokeParticleEngine.clone();
|
|
|
|
smokeParticleEngine.position = mesh.position.clone();
|
|
|
|
smokeParticleEngine.updateInstance('position');
|
|
|
|
smokeParticleEngine.enabled = true;
|
|
|
|
mesh.smokeParticleEngine = smokeParticleEngine;
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.PLAY_AUDIO,
|
|
|
|
{
|
|
|
|
name : 'Audio - Burning'
|
2017-11-24 12:59:37 +01:00
|
|
|
}
|
|
|
|
);
|
2017-11-24 13:15:11 +01:00
|
|
|
|
|
|
|
var fireParticleEngine = this.fireParticleEngine.clone();
|
|
|
|
fireParticleEngine.position = mesh.position.clone();
|
|
|
|
fireParticleEngine.updateInstance('position');
|
|
|
|
fireParticleEngine.enabled = true;
|
|
|
|
mesh.fireParticleEngine = fireParticleEngine;
|
2017-11-24 12:59:37 +01:00
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
this.kill = function(enemy) {
|
|
|
|
/**
|
|
|
|
* 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;
|
2017-11-22 10:24:51 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
2017-11-24 13:15:11 +01:00
|
|
|
event : 'gameRunning',
|
|
|
|
message : 'we have enough trees burning now to start - the enemy will spawn now'
|
2017-11-22 10:24:51 +01:00
|
|
|
}
|
|
|
|
);
|
2017-11-24 13:15:11 +01:00
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'treeBurned',
|
|
|
|
treesBurning : this.treesBurning,
|
|
|
|
treesBurningToStart : this.treesBurningToStart
|
2017-11-22 10:24:51 +01:00
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
);
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
this.minimumRendererRed += 0.01;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
this.fog.density -= 0.00025;
|
|
|
|
if (this.fog.density < 0.0055) {
|
|
|
|
this.fog.density = 0.0055;
|
|
|
|
}
|
|
|
|
this.fog.updateInstance('density');
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (mesh.position.x < 0) {
|
|
|
|
this.leftLight.intensity += 0.07;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (this.leftLight.intensity >= 1) {
|
|
|
|
this.leftLight.intensity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.leftLight.updateInstance('intensity');
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
} else {
|
|
|
|
this.rightLight.intensity += 0.07;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (this.rightLight.intensity >= 1) {
|
|
|
|
this.rightLight.intensity = 1;
|
2017-11-22 10:24:51 +01:00
|
|
|
}
|
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
this.rightLight.updateInstance('intensity');
|
2017-11-22 10:24:51 +01:00
|
|
|
|
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-22 10:24:51 +01:00
|
|
|
GameLib.Event.Emit(
|
2017-11-24 13:15:11 +01:00
|
|
|
GameLib.Event.PLAY_AUDIO,
|
2017-11-22 10:24:51 +01:00
|
|
|
{
|
2017-11-24 13:15:11 +01:00
|
|
|
name : 'Audio - Burning'
|
2017-11-22 10:24:51 +01:00
|
|
|
}
|
|
|
|
);
|
2017-11-24 13:15:11 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_STARTED,
|
|
|
|
{
|
|
|
|
game : this
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.totalTime += data.delta;
|
|
|
|
this.enemySpawnTime += data.delta;
|
|
|
|
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
if (this.mouseIsDown)
|
|
|
|
{
|
2017-11-24 13:15:11 +01:00
|
|
|
this.kanisterTime += data.delta;
|
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
this.renderer.clearColor.r += 0.01;
|
|
|
|
if (this.renderer.clearColor.r > 0.45) {
|
|
|
|
this.renderer.clearColor.r = 0.45;
|
2017-11-24 13:15:11 +01:00
|
|
|
}
|
2017-11-24 14:42:52 +01:00
|
|
|
this.renderer.updateInstance('clearColor');
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
this.throwerLight.intensity += 0.05;
|
|
|
|
if (this.throwerLight.intensity > 2) {
|
|
|
|
this.throwerLight.intensity = 2;
|
2017-11-24 13:15:11 +01:00
|
|
|
}
|
2017-11-24 14:42:52 +01:00
|
|
|
this.throwerLight.updateInstance('intensity');
|
2017-11-24 13:15:11 +01:00
|
|
|
|
|
|
|
var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes);
|
|
|
|
intersects.map(
|
|
|
|
function(intersect) {
|
|
|
|
|
|
|
|
var mesh = intersect.mesh;
|
|
|
|
|
|
|
|
if (mesh.name.indexOf('Kanister') !== -1) {
|
|
|
|
this.explodeKanister();
|
|
|
|
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) {
|
|
|
|
|
|
|
|
mesh.instance.material.color.sub(this.toBlack);
|
|
|
|
|
|
|
|
mesh.materials[0].color.r = mesh.instance.material.color.r;
|
|
|
|
mesh.materials[0].color.g = mesh.instance.material.color.g;
|
|
|
|
mesh.materials[0].color.b = mesh.instance.material.color.b;
|
|
|
|
|
|
|
|
mesh.materials[0].color.instance = mesh.instance.material.color;
|
|
|
|
|
|
|
|
if (mesh.instance.material.color.r <= 0) {
|
|
|
|
|
|
|
|
this.burn(mesh);
|
|
|
|
|
|
|
|
if (mesh.instance.material.emissive) {
|
|
|
|
mesh.instance.material.emissive.add(this.toRed);
|
|
|
|
mesh.instance.material.emissive.add(this.toRed);
|
|
|
|
|
|
|
|
if (mesh.instance.material.emissive.r >= 0.8) {
|
|
|
|
this.explode(mesh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* This happens to trees
|
|
|
|
*/
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(mesh.life)) {
|
|
|
|
mesh.life = 1.2;
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh.life -= 0.2;
|
|
|
|
|
|
|
|
if (mesh.life <= 0) {
|
|
|
|
this.burnTree(mesh);
|
|
|
|
|
|
|
|
if (mesh.instance.material.emissive) {
|
|
|
|
mesh.instance.material.emissive.add(this.toRed);
|
|
|
|
mesh.instance.material.emissive.add(this.toRed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.kanisterTime += (data.delta * this.kanisterLeakTime);
|
2017-11-24 13:15:11 +01:00
|
|
|
|
|
|
|
this.renderer.clearColor.r -= 0.01;
|
|
|
|
if (this.renderer.clearColor.r < this.minimumRendererRed) {
|
|
|
|
this.renderer.clearColor.r = this.minimumRendererRed;
|
|
|
|
}
|
|
|
|
this.renderer.updateInstance('clearColor');
|
|
|
|
|
|
|
|
this.throwerLight.intensity -= 0.05;
|
|
|
|
if (this.throwerLight.intensity < 0) {
|
|
|
|
this.throwerLight.intensity = 0;
|
|
|
|
}
|
|
|
|
this.throwerLight.updateInstance('intensity');
|
|
|
|
}
|
|
|
|
|
2017-11-24 15:28:28 +01:00
|
|
|
var used = this.kanisterTime / this.kanisterLife;
|
2017-11-24 15:39:14 +01:00
|
|
|
|
2017-11-24 15:47:09 +01:00
|
|
|
console.log(used);
|
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'fuelUsed',
|
2017-11-24 15:28:28 +01:00
|
|
|
used : used,
|
|
|
|
percentage : Math.round(used * 100) + '%',
|
|
|
|
kanisters : this.kanisters
|
2017-11-24 14:42:52 +01:00
|
|
|
}
|
|
|
|
);
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
if (this.kanisterTime > this.kanisterLife) {
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
this.kanisterTime = 0;
|
|
|
|
this.kanisters -= 1;
|
2017-11-24 13:15:11 +01:00
|
|
|
|
2017-11-24 15:36:17 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'kanisterCountUpdate',
|
2017-11-24 15:44:04 +01:00
|
|
|
kanisters : this.kanisters
|
2017-11-24 15:36:17 +01:00
|
|
|
}
|
|
|
|
);
|
2017-11-24 15:39:14 +01:00
|
|
|
|
2017-11-24 15:47:09 +01:00
|
|
|
if (this.kanisters < 0) {
|
2017-11-24 14:42:52 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_OVER,
|
|
|
|
{
|
|
|
|
game : this
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-11-24 13:15:11 +01:00
|
|
|
}
|
|
|
|
|
2017-11-24 14:42:52 +01:00
|
|
|
if (this.enemySpawnTime > this.enemySpawnInterval && this.running) {
|
|
|
|
this.enemySpawnTime = 0;
|
|
|
|
this.spawnEnemy();
|
2017-11-24 13:15:11 +01:00
|
|
|
}
|
2017-11-24 14:42:52 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
// if (this.kanister.explodeParticleEngine) {
|
|
|
|
// if (GameLib.Utils.UndefinedOrNull(this.kanister.waiting)) {
|
|
|
|
// this.kanister.waiting = true;
|
|
|
|
// } else {
|
|
|
|
// this.kanister.explodeParticleEngine.remove();
|
|
|
|
// this.kanister.explodeParticleEngine = null;
|
|
|
|
// delete this.kanister.waiting;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (this.kanisterTime > (this.kanisterLife / 2)) {
|
|
|
|
//
|
|
|
|
// this.kanister.visible = true;
|
|
|
|
// this.kanister.updateInstance('visible');
|
|
|
|
//
|
|
|
|
// GameLib.Event.Emit(
|
|
|
|
// GameLib.Event.GAME_DATA,
|
|
|
|
// {
|
|
|
|
// event : 'kanisterAppeared'
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
// }
|
2017-11-24 13:15:11 +01:00
|
|
|
|
|
|
|
this.enemies = this.enemies.reduce(
|
|
|
|
function(result, enemy) {
|
|
|
|
|
|
|
|
if (enemy.exploding === true) {
|
|
|
|
/**
|
2017-11-22 10:24:51 +01:00
|
|
|
* We need to wait one render cycle for the smoke explode particle engine
|
|
|
|
* and then kill the enemy
|
|
|
|
*/
|
2017-11-24 13:15:11 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(enemy.waiting)) {
|
|
|
|
enemy.waiting = true;
|
|
|
|
result.push(enemy);
|
|
|
|
} else {
|
|
|
|
this.kill(enemy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
enemy.mesh.position.add(enemy.velocity);
|
|
|
|
enemy.mesh.updateInstancePosition();
|
|
|
|
|
|
|
|
enemy.mesh.quaternion.angle += enemy.rotation.angle;
|
|
|
|
enemy.mesh.updateInstanceRotation();
|
|
|
|
|
|
|
|
enemy.lifeTime += data.delta;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (enemy.lifeTime > enemy.life) {
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GAME_DATA,
|
|
|
|
{
|
|
|
|
event : 'enemyLifetimeReached',
|
|
|
|
enemy : enemy
|
|
|
|
}
|
|
|
|
);
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
/**
|
2017-11-22 10:24:51 +01:00
|
|
|
* We only remove the things we cloned
|
|
|
|
*/
|
2017-11-24 13:15:11 +01:00
|
|
|
this.kill(enemy);
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
return result;
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
} else {
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (enemy.burning) {
|
2017-11-24 14:42:52 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
enemy.burnTime += data.delta;
|
2017-11-24 14:42:52 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
if (enemy.burnTime > enemy.burnLife) {
|
|
|
|
enemy.mesh.smokeParticleEngine.remove();
|
|
|
|
enemy.mesh.fireParticleEngine.remove();
|
|
|
|
enemy.lifeTime = enemy.life + 1;
|
|
|
|
} else {
|
|
|
|
enemy.mesh.smokeParticleEngine.position = enemy.mesh.position.clone();
|
|
|
|
enemy.mesh.smokeParticleEngine.updateInstance('position');
|
|
|
|
enemy.mesh.fireParticleEngine.position = enemy.mesh.position.clone();
|
|
|
|
enemy.mesh.fireParticleEngine.updateInstance('position');
|
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
enemy.mesh.materials[0].opacity -= 0.005;
|
|
|
|
enemy.mesh.materials[0].updateInstance('opacity');
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
result.push(enemy);
|
|
|
|
return result;
|
|
|
|
}
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
}.bind(this),
|
|
|
|
[]
|
|
|
|
);
|
2017-11-22 10:24:51 +01:00
|
|
|
|
2017-11-24 13:15:11 +01:00
|
|
|
return null;
|
2017-11-22 10:24:51 +01:00
|
|
|
//# sourceURL=beforeRender.js
|