Scene.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var game = Atomic.game;
  2. var node = self.node;
  3. var world;
  4. var drawDebug = false;
  5. var debugRenderer;
  6. function start() {
  7. var scene = game.scene;
  8. // debug renderer for showing physics
  9. if (drawDebug)
  10. debugRenderer = scene.createComponent("DebugRenderer");
  11. // zone
  12. var zoneNode = scene.createChild("Zone")
  13. var zone = zoneNode.createComponent("Zone");
  14. zone.boundingBox = [-1000, -1000, -1000, 1000, 1000, 1000];
  15. zone.ambientColor = [0.15, 0.15, 0.15];
  16. zone.fogColor = [0.5, 0.5, 0.7, 1.0];
  17. zone.fogStart = 10;
  18. zone.fogEnd = 100;
  19. var lightNode = scene.createChild("Directional Light");
  20. lightNode.direction = [0.6, -1.0, 0.8];
  21. var light = lightNode.createComponent("Light")
  22. light.lightType = Atomic.LIGHT_DIRECTIONAL;
  23. light.castShadows = true;
  24. // If we're running on android tweak the shadows
  25. if (Atomic.platform == "Android") {
  26. light.setShadowCascade(20.0, 50.0, 200.0, 0.0, 0.9);
  27. light.shadowIntensity = 0.33;
  28. } else {
  29. light.setShadowCascade(10.0, 50.0, 200.0, 0.0, 0.8);
  30. }
  31. light.setShadowBias(0.00025, 0.5);
  32. light.specularIntensity = 8;
  33. // add the roboman
  34. var roboman = node.createChild("TheRoboMan");
  35. roboman.createJSComponent("RoboMan");
  36. roboman.position = [0, 0, -10];
  37. roboman.scale = [.5, .5, .5];
  38. // Adding scene elements
  39. var barrels = node.createChild("Barrels");
  40. barrels.createJSComponent("Barrels");
  41. var barrels = node.createChild("Barrels02");
  42. barrels.createJSComponent("Barrels02");
  43. var ground = node.createChild("Ground");
  44. ground.createJSComponent("Ground");
  45. var fence = node.createChild("Fence");
  46. fence.createJSComponent("Fence");
  47. var fence = node.createChild("Fence02");
  48. fence.createJSComponent("Fence02");
  49. var fence = node.createChild("Fence03");
  50. fence.createJSComponent("Fence03");
  51. var house = node.createChild("House");
  52. house.createJSComponent("House");
  53. var house = node.createChild("House02");
  54. house.createJSComponent("House02");
  55. var house = node.createChild("House03");
  56. house.createJSComponent("House03");
  57. // Adding the bgm
  58. var musicFile = game.cache.getResource("Sound", "Music/StoryTime.ogg");
  59. musicFile.looped = true;
  60. var musicNode = scene.createChild("MusicNode");
  61. var musicSource = musicNode.createComponent("SoundSource");
  62. musicSource.gain = .5;
  63. musicSource.soundType = Atomic.SOUND_MUSIC;
  64. musicSource.play(musicFile);
  65. }
  66. function postRenderUpdate() {
  67. world.drawDebugGeometry(debugRenderer, true);
  68. }
  69. // we need an update or it doesn't run the start, fix in JSVM
  70. function update(timeStep) {
  71. if (drawDebug)
  72. self.listenToEvent(null, "PostRenderUpdate", postRenderUpdate);
  73. }