if (!this.entityLoaded) { return; } if (GameLib.Utils.UndefinedOrNull(this.initialized)) { this.initialized = true; this.bull = this.entityLoaded.bull; this.star = this.entityLoaded.star; this.burger = this.entityLoaded.burger; this.parcel = this.entityLoaded.parcel; this.santa = this.entityLoaded.santa; this.renderer = this.entityLoaded.renderer; this.raycaster = this.entityLoaded.raycaster; this.toBlack = new THREE.Color(0.05, 0.05, 0.05); this.bull.instance.visible = false; this.star.instance.visible = false; this.burger.instance.visible = false; this.parcel.instance.visible = false; this.santa.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, 1 ); } this.nextSpawnTime = this.getNextSpawnTime(); this.spawnEnemy = function() { var enemyType = GameLib.Utils.GetRandomIntInclusive(1, 5); var meshType = GameLib.Utils.GetRandomIntInclusive(1, 5); var y = GameLib.Utils.GetRandomIntInclusive(2, 10); var speed = 1; var material = null; var mesh = null; if (meshType === 1) { mesh = this.bull.clone(); material = this.bull.materials[0].clone(); speed = 0.2; } else if (meshType === 2) { mesh = this.star.clone(); material = this.star.materials[0].clone(); speed = 0.3; } else if (meshType === 3) { mesh = this.burger.clone(); material = this.burger.materials[0].clone(); speed = 0.4; } else if (meshType === 4) { mesh = this.parcel.clone(); material = this.parcel.materials[0].clone(); speed = 0.5; } else if (meshType === 5) { mesh = this.santa.clone(); material = this.santa.materials[0].clone(); speed = 0.5; } else { console.log('unknown mesh type : ' + meshType); } mesh.materials = [material]; mesh.updateInstance(); mesh.instance.visible = true; var velocity = null; var axis = new GameLib.API.Vector3( GameLib.Utils.GetRandomIntInclusive(1,10) * 0.1, GameLib.Utils.GetRandomIntInclusive(1,10) * 0.1, GameLib.Utils.GetRandomIntInclusive(1,10) * 0.1 ); axis = axis.normalize(); var angle = GameLib.Utils.GetRandomIntInclusive(1,100) * 0.001; var position = {x : 0, y: y, z :0}; var rotation = { axis : axis, angle : angle }; 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.useQuaternion = true; enemy.mesh.quaternion.axis.x = rotation.axis.x; enemy.mesh.quaternion.axis.y = rotation.axis.y; enemy.mesh.quaternion.axis.z = rotation.axis.z; enemy.mesh.quaternion.angle = rotation.angle; enemy.mesh.updateInstanceRotation(); enemy.velocity = velocity; enemy.rotation = rotation; enemy.lifeTime = 0; enemy.life = 15; this.enemies.push(enemy); } } this.totalTime += data.delta; this.spawnTime += data.delta; if (this.mouseIsDown) { this.renderer.clearColor.r += 0.01; if (this.renderer.clearColor.r > 1) { this.renderer.clearColor.r = 1; } this.renderer.updateInstance('clearColor'); var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes); intersects.map( function(intersect) { var mesh = intersect.mesh; if ( mesh.id !== 'ykfzwmaw9j' && //crosshair mesh.id !== 't3uije6lwm' && //floor mesh.id !== 'x4rhvbj8cn' && //flamethrower mesh.id !== 'xztyfgwq7i' && //skybox mesh.name.indexOf('Stone') === -1 //stones ) { if (mesh.instance.material instanceof Array) { mesh.instance.material.map( function(material) { material.color.sub(this.toBlack); } ); } else { mesh.instance.material.color.sub(this.toBlack); } } }.bind(this) ); } else { this.renderer.clearColor.r -= 0.01; if (this.renderer.clearColor.r < 0) { this.renderer.clearColor.r = 0; } this.renderer.updateInstance('clearColor'); } if (this.spawnTime > this.nextSpawnTime) { 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.quaternion.angle += enemy.rotation.angle; enemy.mesh.updateInstanceRotation(); 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