r3-custom-code/9l6o7974qx.js

154 lines
2.9 KiB
JavaScript

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