Browse Source

Day and night

Josh Engebretson 11 years ago
parent
commit
ec824b72ec

+ 3 - 1
PhysicsPlatformer/Resources/Components/Avatar.js

@@ -23,7 +23,8 @@ light.numRays = 256;
 light.backtrace = true;
 self.light = light;
 
-lightGroup.addLight(light);
+if (!daytime)
+    lightGroup.addLight(light);
 
 node.createJSComponent("LightFlicker");
 
@@ -36,6 +37,7 @@ var body = node.createComponent("RigidBody2D");
 body.setBodyType(Atomic.BT_DYNAMIC);
 body.fixedRotation = true;
 body.bullet = true;
+body.castShadows = false;
 
 var circle = node.createComponent("CollisionCircle2D");
 // Set radius

+ 2 - 1
PhysicsPlatformer/Resources/Components/Bat.js

@@ -19,7 +19,8 @@ var light = node.createComponent("PointLight2D");
 light.color = [1, 1, 1, 1];
 light.radius = 4;
 
-lightGroup.addLight(light);
+if (!daytime)
+    lightGroup.addLight(light);
 
 node.createJSComponent("LightFlicker");
 

+ 2 - 0
PhysicsPlatformer/Resources/Components/Vine.js

@@ -12,6 +12,7 @@ function start() {
 
     // create the node body
     var groundBody = node.createComponent("RigidBody2D");
+    groundBody.castShadows = false;
 
     var prevBody = groundBody;
 
@@ -24,6 +25,7 @@ function start() {
         sprite2D.sprite = cache.getResource("Sprite2D", "Sprites/vine.png");
         
         var vbody = vnode.createComponent("RigidBody2D");
+        vbody.castShadows = false;
         vbody.bodyType = Atomic.BT_DYNAMIC;
 
         // Create box

+ 20 - 2
PhysicsPlatformer/Resources/PhysicsPlatformer.js

@@ -6,6 +6,7 @@ input = GetInput();
 ui = GetUI();
 gameui = GetGameUI();
 
+
 var halfWidth = graphics.width * Atomic.PIXEL_SIZE * 0.5;
 var halfHeight = graphics.height * Atomic.PIXEL_SIZE * 0.5;
 var enableDebugHud = false;
@@ -31,6 +32,8 @@ function Update() {
 
 function CreateScene() {
 
+    daytime = true;
+
     scene = new Atomic.Scene();
     scene.createComponent("Octree");
     scene.createComponent("DebugRenderer");
@@ -53,8 +56,23 @@ function CreateScene() {
     lightGroupNode = scene.createChild("LightGroup");
     lightGroup = lightGroupNode.createComponent("Light2DGroup");
     lightGroup.setPhysicsWorld(physicsWorld);
-    lightGroup.ambientColor = [.8, .8, .8, .5];
-        
+    if (daytime)
+        lightGroup.ambientColor = [1, 1, 1, .9];
+    else
+        lightGroup.ambientColor = [.8, .8, .8, .5];
+    
+    
+    if (daytime)
+    {
+        TheSun = scene.createComponent("DirectionalLight2D");
+        TheSun.color = [1, 1, 1, 0.15];
+        TheSun.castShadows = true;
+        TheSun.softShadows = true;
+        TheSun.softShadowLength = 20;
+        TheSun.numRays = 1024;
+        TheSun.backtrace = false;        
+        lightGroup.addLight(TheSun);
+    }
     
     uiNode = scene.createChild("UI");
     uiNode.createJSComponent("UI");