Initial Commit: CC - Before Render - Moorcow (9l6o7974qx.js)
parent
b9fbd05bc6
commit
e7c95c60ca
|
@ -0,0 +1,125 @@
|
|||
if (
|
||||
GameLib.Utils.UndefinedOrNull(this.totalTime) ||
|
||||
GameLib.Utils.UndefinedOrNull(this.spawnTime)
|
||||
) {
|
||||
|
||||
/**
|
||||
* 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,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
this.scene = GameLib.EntityManager.Instance.findComponentById('lpdxa66480');
|
||||
|
||||
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 = GameLib.EntityManager.Instance.findComponentById('3upawmhh8j');
|
||||
|
||||
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};
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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
|
Loading…
Reference in New Issue