From 7d95e45659f003f13d70e5d0bb1c07d127778691 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Tue, 31 Oct 2017 12:56:28 +0100 Subject: [PATCH] Initial Commit: Custom Code - BK Flame - Before Render (dywmtohrda.js) --- dywmtohrda.js | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 dywmtohrda.js diff --git a/dywmtohrda.js b/dywmtohrda.js new file mode 100644 index 0000000..79001e2 --- /dev/null +++ b/dywmtohrda.js @@ -0,0 +1,209 @@ +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}; + } + + 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 + }); + + var position = this.camera.lookAt.instance.clone(); + var origin = this.camera.position.instance.clone(); + + var mInverse = new THREE.Matrix4().getInverse( this.sceneCrosshair.instance.matrixWorld ); + + position.applyMatrix4( mInverse ); + + var geometry = new THREE.Geometry(); + geometry.vertices.push( + new THREE.Vector3( + this.camera.position.x, + this.camera.position.y, + 0 + ), + position + ); + + 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) { + child.position.y -= 0.01; + } + } +); + +//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 \ No newline at end of file