diff --git a/qi81k80v08.js b/qi81k80v08.js index 5ec8a82..fc24fdf 100644 --- a/qi81k80v08.js +++ b/qi81k80v08.js @@ -1,165 +1,165 @@ if (!this.entityLoaded) { - return; + return; } if (GameLib.Utils.UndefinedOrNull(this.loaded)) { - - this.loaded = true; - - this.bull = this.entityLoaded.bull; - this.star = this.entityLoaded.star; - this.burger = this.entityLoaded.burger; - this.parcel = this.entityLoaded.parcel; - - this.bull.instance.visible = false; - this.star.instance.visible = false; - this.burger.instance.visible = false; - this.parcel.instance.visible = false; - - /** - * 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, - 10 - ); - } - - this.nextSpawnTime = this.getNextSpawnTime(); - - this.spawnEnemy = function() { + this.loaded = true; - var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); - var meshType = GameLib.Utils.GetRandomIntInclusive(1, 4); - - var y = GameLib.Utils.GetRandomIntInclusive(2, 10)); + this.bull = this.entityLoaded.bull; + this.star = this.entityLoaded.star; + this.burger = this.entityLoaded.burger; + this.parcel = this.entityLoaded.parcel; - var apiBox = new GameLib.D3.API.Mesh(); + this.bull.instance.visible = false; + this.star.instance.visible = false; + this.burger.instance.visible = false; + this.parcel.instance.visible = false; - apiBox.materials = [this.boxMaterial]; + /** + * This component is initializing - set the total time to 0 + */ + this.totalTime = 0; + this.spawnTime = 0; - var speed = 1; - - var mesh = null; - if (meshType === 1) { - mesh = this.bull.clone(); - speed = 0.2; - } else if (meshType === 2) { - mesh = this.star.clone(); - speed = 0.3; - } else if (meshType === 3) { - mesh = this.burger.clone(); - speed = 0.4; - } else if (meshType === 4) { - mesh = this.parcel.clone(); - speed = 0.5; - } else { - console.log('unknown mesh type : ' + meshType); - } - - mesh.instance.visible = true; - - var velocity = null; + this.enemies = []; - 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}; + GameLib.Event.Emit( + GameLib.Event.GET_GRAPHICS_IMPLEMENTATION, + null, + function(graphics) { + this.graphics = graphics + }.bind(this) + ); - var rotation = {x : rotX, y: rotY, z: rotZ}; - - var enemy = { - mesh : mesh - }; + this.getNextSpawnTime = function() { + return GameLib.Utils.GetRandomIntInclusive( + 1, + 10 + ); + } - if (enemyType === 1) { - position.x = -100; - velocity = {x:speed,y:0,z:0}; - } + this.nextSpawnTime = this.getNextSpawnTime(); - if (enemyType === 2) { - position.x = 100; - velocity = {x:-speed,y:0,z:0}; - } + this.spawnEnemy = function() { - if (enemyType === 3) { - position.x = -100; - position.z = -100; - velocity = {x:speed,y:0,z:speed}; - } + var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); + var meshType = GameLib.Utils.GetRandomIntInclusive(1, 4); - if (enemyType === 4) { - position.x = 100; - position.z = -100; - velocity = {x:-speed,y:0,z:speed}; - } + var y = GameLib.Utils.GetRandomIntInclusive(2, 10); - if (enemyType === 5) { - position.x = 0; - position.z = -100; - velocity = {x:0,y:0,z:speed}; - } + var apiBox = new GameLib.D3.API.Mesh(); + + apiBox.materials = [this.boxMaterial]; + + var speed = 1; + + var mesh = null; + if (meshType === 1) { + mesh = this.bull.clone(); + speed = 0.2; + } else if (meshType === 2) { + mesh = this.star.clone(); + speed = 0.3; + } else if (meshType === 3) { + mesh = this.burger.clone(); + speed = 0.4; + } else if (meshType === 4) { + mesh = this.parcel.clone(); + speed = 0.5; + } else { + console.log('unknown mesh type : ' + meshType); + } + + mesh.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 : mesh + }; + + 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.mesh.position.x = position.x; + enemy.mesh.position.y = position.y; + enemy.mesh.position.z = position.z; + enemy.mesh.updateInstancePosition(); - enemy.velocity = velocity; - enemy.rotation = rotation; - - enemy.lifeTime = 0; - enemy.life = 15; + enemy.velocity = velocity; + enemy.rotation = rotation; - this.enemies.push(enemy); - } + 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.nextSpawnTime = this.getNextSpawnTime(); + this.spawnTime = 0; + this.spawnEnemy(); } this.enemies = this.enemies.reduce( - function(result, enemy) { - enemy.mesh.position.add(enemy.velocity); - enemy.mesh.updateInstancePosition(); - - enemy.mesh.rotation.add(enemy.rotation); - 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; - }, - [] + function(result, enemy) { + enemy.mesh.position.add(enemy.velocity); + enemy.mesh.updateInstancePosition(); + + enemy.mesh.rotation.add(enemy.rotation); + 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;