2017-10-31 12:56:28 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(this.entityLoaded)) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This component is not ready to run
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
GameLib.Utils.UndefinedOrNull(this.totalTime) ||
|
|
|
|
GameLib.Utils.UndefinedOrNull(this.spawnTime) ||
|
|
|
|
GameLib.Utils.UndefinedOrNull(this.spawnBulletFrequency) ||
|
|
|
|
GameLib.Utils.UndefinedOrNull(this.camera) ||
|
|
|
|
GameLib.Utils.UndefinedOrNull(this.scene) ||
|
|
|
|
GameLib.Utils.UndefinedOrNull(this.sceneCrosshair)
|
|
|
|
// true
|
|
|
|
) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This component is initializing - set the total time to 0
|
|
|
|
*/
|
|
|
|
this.totalTime = 0;
|
|
|
|
this.spawnTime = 0;
|
|
|
|
this.spawnBulletFrequency = 0.1;
|
|
|
|
|
|
|
|
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(
|
|
|
|
GameLib.D3.CustomCode.MIN_SPAWN_TIME,
|
|
|
|
GameLib.D3.CustomCode.MAX_SPAWN_TIME
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.boxMaterial = GameLib.EntityManager.Instance.findComponentById('dsaua5t19a');
|
|
|
|
|
|
|
|
this.tree = GameLib.EntityManager.Instance.findComponentById('fcj62ukx5s');
|
|
|
|
|
|
|
|
this.camera = GameLib.EntityManager.Instance.findComponentById('yv62w8sx9r');
|
|
|
|
this.scene = GameLib.EntityManager.Instance.findComponentById('fd2be8y1c8');
|
|
|
|
this.sceneCrosshair = GameLib.EntityManager.Instance.findComponentById('7xkcp6x9pf');
|
|
|
|
this.meshCrosshair = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv');
|
|
|
|
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
var tree = this.tree.clone();
|
|
|
|
tree.position.x = Math.floor(Math.random() * 1000) - 500;
|
|
|
|
tree.position.y = Math.floor(Math.random() * 60) - 30;
|
|
|
|
tree.position.z = Math.floor(Math.random() * 1000) - 500;
|
|
|
|
tree.updateInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.tree.position.x = Math.floor(Math.random() * 1000) - 500;
|
|
|
|
this.tree.position.y = Math.floor(Math.random() * 60) - 30;
|
|
|
|
this.tree.position.z = Math.floor(Math.random() * 1000) - 500;
|
|
|
|
|
|
|
|
this.tree.updateInstance();
|
|
|
|
|
|
|
|
this.nextSpawnTime = this.getNextSpawnTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.spawnEnemy = function() {
|
|
|
|
|
|
|
|
var enemyType = Math.floor((Math.random() * 5) + 1);
|
|
|
|
|
|
|
|
var y = Math.floor((Math.random() * 40) + 2);
|
|
|
|
|
|
|
|
var apiBox = new GameLib.D3.API.Mesh();
|
|
|
|
|
|
|
|
apiBox.materials = [this.boxMaterial];
|
|
|
|
|
|
|
|
var box = new GameLib.D3.Mesh.Box(this.graphics, apiBox, 4,4,4);
|
|
|
|
|
|
|
|
var velocity = null;
|
|
|
|
|
|
|
|
var position = {x : 0, y: y, z :0};
|
|
|
|
|
|
|
|
var enemy = {
|
|
|
|
mesh : box
|
|
|
|
};
|
|
|
|
|
|
|
|
if (enemyType === 1) {
|
|
|
|
position.x = -500;
|
|
|
|
velocity = {x:1,y:0,z:0};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemyType === 2) {
|
|
|
|
position.x = 500;
|
|
|
|
velocity = {x:-1,y:0,z:0};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemyType === 3) {
|
|
|
|
position.x = -500;
|
|
|
|
position.z = -500;
|
|
|
|
velocity = {x:1,y:0,z:1};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemyType === 4) {
|
|
|
|
position.x = 500;
|
|
|
|
position.z = -500;
|
|
|
|
velocity = {x:-1,y:0,z:1};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enemyType === 5) {
|
|
|
|
position.x = 0;
|
|
|
|
position.z = -500;
|
|
|
|
velocity = {x:0,y:0,z:1};
|
|
|
|
}
|
|
|
|
|
2017-10-31 13:12:35 +01:00
|
|
|
|
2017-10-31 12:56:28 +01:00
|
|
|
enemy.mesh.position.x = position.x;
|
|
|
|
enemy.mesh.position.y = position.y;
|
|
|
|
enemy.mesh.position.z = position.z;
|
|
|
|
enemy.mesh.updateInstancePosition();
|
|
|
|
|
|
|
|
enemy.velocity = velocity;
|
|
|
|
enemy.lifeTime = 0;
|
|
|
|
enemy.life = 50;
|
|
|
|
|
|
|
|
this.enemies.push(enemy);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.totalTime += data.delta;
|
|
|
|
this.spawnTime += data.delta;
|
|
|
|
|
|
|
|
if (this.spawnTime > this.nextSpawnTime) {
|
|
|
|
this.nextSpawnTime = Math.floor((Math.random() * 1) + 1);
|
|
|
|
this.spawnTime = 0;
|
|
|
|
this.spawnEnemy();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.spawningBullets === true) {
|
|
|
|
|
|
|
|
if (this.spawnBulletTime === 0) {
|
|
|
|
|
|
|
|
var material = new THREE.LineBasicMaterial({
|
|
|
|
color: 0xff0000,
|
|
|
|
linewidth: 5
|
|
|
|
});
|
|
|
|
|
2017-10-31 13:12:35 +01:00
|
|
|
var position = this.camera.position.instance.clone();
|
|
|
|
var lookAt = this.camera.lookAt.instance.clone();
|
2017-10-31 12:56:28 +01:00
|
|
|
|
2017-10-31 13:49:21 +01:00
|
|
|
//var direction = position.sub(lookAt);
|
2017-10-31 12:56:28 +01:00
|
|
|
|
2017-10-31 13:46:34 +01:00
|
|
|
|
2017-10-31 13:49:21 +01:00
|
|
|
console.log(position);
|
2017-10-31 13:46:34 +01:00
|
|
|
|
|
|
|
//var mInverse = new THREE.Matrix4().getInverse( this.sceneCrosshair.instance.matrixWorld );
|
|
|
|
|
|
|
|
//position.applyMatrix4( mInverse );
|
2017-10-31 12:56:28 +01:00
|
|
|
|
|
|
|
var geometry = new THREE.Geometry();
|
|
|
|
geometry.vertices.push(
|
2017-10-31 13:49:35 +01:00
|
|
|
position,
|
|
|
|
lookAt
|
2017-10-31 12:56:28 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
var line = new THREE.Line( geometry, material );
|
|
|
|
this.scene.instance.add( line );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.spawnBulletTime += data.delta;
|
|
|
|
|
|
|
|
if (this.spawnBulletTime > this.spawnBulletFrequency) {
|
|
|
|
this.spawnBulletTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.scene.instance.children.map(
|
|
|
|
function(child) {
|
|
|
|
if (child instanceof THREE.Line) {
|
2017-10-31 13:39:19 +01:00
|
|
|
// child.position.y -= 0.01;
|
2017-10-31 12:56:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
//this.entityLoaded.updateMaterialRusted(this.totalTime);
|
|
|
|
|
|
|
|
this.enemies = this.enemies.reduce(
|
|
|
|
function(result, enemy) {
|
|
|
|
enemy.mesh.position.add(enemy.velocity);
|
|
|
|
enemy.mesh.updateInstancePosition();
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
//# sourceURL=beforeRender.js
|