From e7c95c60ca8b91805de613009d4df494e7fb72fc Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 6 Nov 2017 23:54:34 +0100 Subject: [PATCH] Initial Commit: CC - Before Render - Moorcow (9l6o7974qx.js) --- 9l6o7974qx.js | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 9l6o7974qx.js diff --git a/9l6o7974qx.js b/9l6o7974qx.js new file mode 100644 index 0000000..8bc69f6 --- /dev/null +++ b/9l6o7974qx.js @@ -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 \ No newline at end of file