2017-11-07 00:33:04 +01:00
|
|
|
if (!this.entityLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
if (
|
2018-04-10 15:48:32 +02:00
|
|
|
R3.Utils.UndefinedOrNull(this.totalTime) ||
|
|
|
|
R3.Utils.UndefinedOrNull(this.spawnTime)
|
2017-11-06 23:54:34 +01:00
|
|
|
) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This component is initializing - set the total time to 0
|
|
|
|
*/
|
|
|
|
this.totalTime = 0;
|
|
|
|
this.spawnTime = 0;
|
2017-11-07 00:13:34 +01:00
|
|
|
|
2018-04-10 15:48:32 +02:00
|
|
|
var cow = R3.EntityManager.Instance.findComponentById('3upawmhh8j');
|
|
|
|
var burger = R3.EntityManager.Instance.findComponentById('psy2g7qsfx');
|
2017-11-07 00:13:34 +01:00
|
|
|
|
|
|
|
cow.instance.visible = false;
|
2017-11-07 00:23:08 +01:00
|
|
|
burger.instance.visible = false;
|
2017-11-06 23:54:34 +01:00
|
|
|
|
|
|
|
this.enemies = [];
|
|
|
|
|
2018-04-10 15:48:32 +02:00
|
|
|
R3.Event.Emit(
|
|
|
|
R3.Event.GET_GRAPHICS_IMPLEMENTATION,
|
2017-11-06 23:54:34 +01:00
|
|
|
null,
|
|
|
|
function(graphics) {
|
|
|
|
this.graphics = graphics
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
this.getNextSpawnTime = function() {
|
2018-04-10 15:48:32 +02:00
|
|
|
return R3.Utils.GetRandomIntInclusive(
|
2017-11-06 23:54:34 +01:00
|
|
|
1,
|
2017-11-07 00:06:03 +01:00
|
|
|
10
|
2017-11-06 23:54:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-10 15:48:32 +02:00
|
|
|
this.scene = R3.EntityManager.Instance.findComponentById('lpdxa66480');
|
2017-11-06 23:54:34 +01:00
|
|
|
|
|
|
|
this.nextSpawnTime = this.getNextSpawnTime();
|
|
|
|
|
2017-11-06 23:57:44 +01:00
|
|
|
this.spawnEnemy = function() {
|
2017-11-06 23:54:34 +01:00
|
|
|
|
|
|
|
var enemyType = Math.floor((Math.random() * 5) + 1);
|
2017-11-07 00:23:08 +01:00
|
|
|
var meshType = Math.floor((Math.random() * 2) + 1);
|
|
|
|
|
2017-11-07 00:06:03 +01:00
|
|
|
var y = Math.floor((Math.random() * 10) + 2);
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2018-04-10 15:48:32 +02:00
|
|
|
var apiBox = new R3.D3.API.Mesh();
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
apiBox.materials = [this.boxMaterial];
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-07 00:39:11 +01:00
|
|
|
var speed = 0.5;
|
|
|
|
|
2017-11-07 00:23:08 +01:00
|
|
|
var box = null;
|
|
|
|
if (meshType === 1) {
|
|
|
|
box = cow.clone();
|
|
|
|
} else {
|
|
|
|
box = burger.clone();
|
2017-11-07 00:39:11 +01:00
|
|
|
speed = 0.3;
|
2017-11-07 00:23:08 +01:00
|
|
|
}
|
2017-11-07 00:10:58 +01:00
|
|
|
|
|
|
|
box.instance.visible = true;
|
2017-11-06 23:54:34 +01:00
|
|
|
|
|
|
|
var velocity = null;
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-07 00:13:34 +01:00
|
|
|
var rotX = Math.floor((Math.random() * 10) + 1) * 0.01;
|
|
|
|
var rotY = Math.floor((Math.random() * 10) + 1) * 0.01;
|
|
|
|
var rotZ = Math.floor((Math.random() * 10) + 1) * 0.01;
|
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
var position = {x : 0, y: y, z :0};
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-07 00:13:34 +01:00
|
|
|
var rotation = {x : rotX, y: rotY, z: rotZ};
|
|
|
|
|
2017-11-07 00:39:11 +01:00
|
|
|
|
2017-11-07 00:07:48 +01:00
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
var enemy = {
|
|
|
|
mesh : box
|
|
|
|
};
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
if (enemyType === 1) {
|
2017-11-07 00:06:03 +01:00
|
|
|
position.x = -100;
|
2017-11-07 00:07:48 +01:00
|
|
|
velocity = {x:speed,y:0,z:0};
|
2017-11-06 23:54:34 +01:00
|
|
|
}
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
if (enemyType === 2) {
|
2017-11-07 00:06:03 +01:00
|
|
|
position.x = 100;
|
2017-11-07 00:07:48 +01:00
|
|
|
velocity = {x:-speed,y:0,z:0};
|
2017-11-06 23:54:34 +01:00
|
|
|
}
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
if (enemyType === 3) {
|
2017-11-07 00:06:03 +01:00
|
|
|
position.x = -100;
|
|
|
|
position.z = -100;
|
2017-11-07 00:07:48 +01:00
|
|
|
velocity = {x:speed,y:0,z:speed};
|
2017-11-06 23:54:34 +01:00
|
|
|
}
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
if (enemyType === 4) {
|
2017-11-07 00:06:03 +01:00
|
|
|
position.x = 100;
|
|
|
|
position.z = -100;
|
2017-11-07 00:07:48 +01:00
|
|
|
velocity = {x:-speed,y:0,z:speed};
|
2017-11-06 23:54:34 +01:00
|
|
|
}
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
if (enemyType === 5) {
|
|
|
|
position.x = 0;
|
2017-11-07 00:06:03 +01:00
|
|
|
position.z = -100;
|
2017-11-07 00:07:48 +01:00
|
|
|
velocity = {x:0,y:0,z:speed};
|
2017-11-06 23:54:34 +01:00
|
|
|
}
|
2017-11-06 23:57:44 +01:00
|
|
|
|
|
|
|
|
2017-11-06 23:54:34 +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-06 23:57:44 +01:00
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
enemy.velocity = velocity;
|
|
|
|
enemy.lifeTime = 0;
|
2017-11-07 00:07:48 +01:00
|
|
|
enemy.life = 15;
|
2017-11-06 23:57:44 +01:00
|
|
|
|
2017-11-06 23:54:34 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2018-04-10 15:48:32 +02:00
|
|
|
R3.Event.Emit(
|
|
|
|
R3.Event.REMOVE_COMPONENT,
|
2017-11-06 23:54:34 +01:00
|
|
|
{
|
|
|
|
component : enemy.mesh
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
result.push(enemy);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
//# sourceURL=beforeRender.js
|