2017-11-09 00:10:48 +01:00
|
|
|
if (!this.entityLoaded) {
|
2017-11-11 08:52:10 +01:00
|
|
|
return;
|
2017-11-09 00:10:48 +01:00
|
|
|
}
|
|
|
|
|
2017-11-11 08:54:29 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(this.initialized)) {
|
2017-11-11 08:52:10 +01:00
|
|
|
|
2017-11-11 08:54:29 +01:00
|
|
|
this.initialized = true;
|
2017-11-11 08:52:10 +01:00
|
|
|
|
|
|
|
this.bull = this.entityLoaded.bull;
|
|
|
|
this.star = this.entityLoaded.star;
|
|
|
|
this.burger = this.entityLoaded.burger;
|
|
|
|
this.parcel = this.entityLoaded.parcel;
|
|
|
|
|
|
|
|
this.bull.instance.visible = false;
|
|
|
|
this.star.instance.visible = false;
|
|
|
|
this.burger.instance.visible = false;
|
|
|
|
this.parcel.instance.visible = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This component is initializing - set the total time to 0
|
|
|
|
*/
|
|
|
|
this.totalTime = 0;
|
|
|
|
this.spawnTime = 0;
|
|
|
|
|
|
|
|
this.enemies = [];
|
|
|
|
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.GET_GRAPHICS_IMPLEMENTATION,
|
|
|
|
null,
|
|
|
|
function(graphics) {
|
|
|
|
this.graphics = graphics
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
this.getNextSpawnTime = function() {
|
|
|
|
return GameLib.Utils.GetRandomIntInclusive(
|
|
|
|
1,
|
2017-11-11 08:56:23 +01:00
|
|
|
1
|
2017-11-11 08:52:10 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.nextSpawnTime = this.getNextSpawnTime();
|
|
|
|
|
|
|
|
this.spawnEnemy = function() {
|
|
|
|
|
|
|
|
var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5);
|
|
|
|
var meshType = GameLib.Utils.GetRandomIntInclusive(1, 4);
|
|
|
|
|
|
|
|
var y = GameLib.Utils.GetRandomIntInclusive(2, 10);
|
|
|
|
|
|
|
|
var apiBox = new GameLib.D3.API.Mesh();
|
|
|
|
|
|
|
|
apiBox.materials = [this.boxMaterial];
|
|
|
|
|
|
|
|
var speed = 1;
|
|
|
|
|
|
|
|
var mesh = null;
|
|
|
|
if (meshType === 1) {
|
|
|
|
mesh = this.bull.clone();
|
|
|
|
speed = 0.2;
|
|
|
|
} else if (meshType === 2) {
|
|
|
|
mesh = this.star.clone();
|
|
|
|
speed = 0.3;
|
|
|
|
} else if (meshType === 3) {
|
|
|
|
mesh = this.burger.clone();
|
|
|
|
speed = 0.4;
|
|
|
|
} else if (meshType === 4) {
|
|
|
|
mesh = this.parcel.clone();
|
|
|
|
speed = 0.5;
|
|
|
|
} else {
|
|
|
|
console.log('unknown mesh type : ' + meshType);
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh.instance.visible = true;
|
|
|
|
|
|
|
|
var velocity = null;
|
|
|
|
|
2017-11-11 09:07:00 +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-11 09:01:08 +01:00
|
|
|
|
2017-11-11 09:07:53 +01:00
|
|
|
axis = axis.normalize();
|
2017-11-11 09:01:08 +01:00
|
|
|
|
2017-11-11 09:07:00 +01:00
|
|
|
var angle = GameLib.Utils.GetRandomIntInclusive(1,100) * 0.001;
|
2017-11-11 08:52:10 +01:00
|
|
|
|
|
|
|
var position = {x : 0, y: y, z :0};
|
|
|
|
|
2017-11-11 09:01:08 +01:00
|
|
|
var rotation = {
|
2017-11-11 09:07:00 +01:00
|
|
|
axis : axis,
|
2017-11-11 09:01:08 +01:00
|
|
|
angle : angle
|
|
|
|
};
|
2017-11-11 08:52:10 +01:00
|
|
|
|
|
|
|
var enemy = {
|
|
|
|
mesh : mesh
|
|
|
|
};
|
|
|
|
|
|
|
|
if (enemyType === 1) {
|
|
|
|
position.x = -100;
|
|
|
|
velocity = {x:speed,y:0,z:0};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemyType === 2) {
|
|
|
|
position.x = 100;
|
|
|
|
velocity = {x:-speed,y:0,z:0};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemyType === 3) {
|
|
|
|
position.x = -100;
|
|
|
|
position.z = -100;
|
|
|
|
velocity = {x:speed,y:0,z:speed};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemyType === 4) {
|
|
|
|
position.x = 100;
|
|
|
|
position.z = -100;
|
|
|
|
velocity = {x:-speed,y:0,z:speed};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemyType === 5) {
|
|
|
|
position.x = 0;
|
|
|
|
position.z = -100;
|
|
|
|
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.updateInstancePosition();
|
|
|
|
|
2017-11-11 09:01:08 +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;
|
2017-11-11 08:56:23 +01:00
|
|
|
enemy.mesh.updateInstanceRotation();
|
|
|
|
|
2017-11-11 08:52:10 +01:00
|
|
|
enemy.velocity = velocity;
|
|
|
|
enemy.rotation = rotation;
|
|
|
|
|
|
|
|
enemy.lifeTime = 0;
|
|
|
|
enemy.life = 15;
|
|
|
|
|
|
|
|
this.enemies.push(enemy);
|
|
|
|
}
|
2017-11-09 00:10:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.totalTime += data.delta;
|
|
|
|
this.spawnTime += data.delta;
|
|
|
|
|
|
|
|
if (this.spawnTime > this.nextSpawnTime) {
|
2017-11-11 08:52:10 +01:00
|
|
|
this.nextSpawnTime = this.getNextSpawnTime();
|
|
|
|
this.spawnTime = 0;
|
|
|
|
this.spawnEnemy();
|
2017-11-09 00:10:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.enemies = this.enemies.reduce(
|
2017-11-11 08:52:10 +01:00
|
|
|
function(result, enemy) {
|
|
|
|
enemy.mesh.position.add(enemy.velocity);
|
|
|
|
enemy.mesh.updateInstancePosition();
|
|
|
|
|
2017-11-11 09:04:10 +01:00
|
|
|
enemy.mesh.quaternion.angle += enemy.rotation.angle;
|
2017-11-11 08:56:23 +01:00
|
|
|
enemy.mesh.updateInstanceRotation();
|
|
|
|
|
2017-11-11 08:52:10 +01:00
|
|
|
enemy.lifeTime += data.delta;
|
|
|
|
if (enemy.lifeTime > enemy.life) {
|
|
|
|
GameLib.Event.Emit(
|
|
|
|
GameLib.Event.REMOVE_COMPONENT,
|
|
|
|
{
|
|
|
|
component : enemy.mesh
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
result.push(enemy);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
[]
|
2017-11-09 00:10:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
//# sourceURL=beforeRender.js
|