From 869db3e5e8a322056f4eebb0a5c3bdfbbb47eae5 Mon Sep 17 00:00:00 2001 From: Martin Vilcans Date: Thu, 28 Nov 2013 17:08:23 +0100 Subject: [PATCH] Move and rotate flashlight a bit randomly --- lib/FlashlightComponent.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/FlashlightComponent.js b/lib/FlashlightComponent.js index fd90909..045c06d 100644 --- a/lib/FlashlightComponent.js +++ b/lib/FlashlightComponent.js @@ -1,12 +1,16 @@ define([ 'goo/entities/components/Component', 'goo/entities/components/LightComponent', + 'goo/entities/components/ScriptComponent', 'goo/renderer/light/SpotLight', + 'goo/noise/ValueNoise', 'lib/Game' ], function( Component, LightComponent, + ScriptComponent, SpotLight, + ValueNoise, Game ) { 'use strict'; @@ -20,6 +24,22 @@ define([ var spotLightEntity = Game.goo.world.createEntity('FlashLight'); spotLightEntity.setComponent(new LightComponent(spotLight)); + var script = new ScriptComponent(); + var time = 0; + script.run = function(entity, tpf, environment) { + time += tpf; + var rotY = (ValueNoise.evaluate1d(time, 1.1) - .5) * .15; + var rotX = (ValueNoise.evaluate1d(time, 1.3) - .5) * .13; + var posX = (ValueNoise.evaluate1d(time + 11919, 1.3) - .5) * .2; + var posY = (ValueNoise.evaluate1d(time + 31900, 1.3) - .5) * .2; + spotLightEntity.transformComponent.transform.translation.setd(posX, posY, 0); + spotLightEntity.transformComponent.setRotation(rotX, rotY, 0); + spotLightEntity.transformComponent.setUpdated(); + + spotLight.intensity = (ValueNoise.evaluate1d(time, 2.3) - .5) * .2;; + } + spotLightEntity.setComponent(script); + spotLightEntity.addToWorld(); Game.viewCam.transformComponent.attachChild( spotLightEntity.transformComponent);