PhysicsPlatformer.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. cache = GetResourceCache();
  2. graphics = GetGraphics();
  3. renderer = GetRenderer();
  4. engine = GetEngine();
  5. input = GetInput();
  6. ui = GetUI();
  7. gameui = GetGameUI();
  8. var halfWidth = graphics.width * Atomic.PIXEL_SIZE * 0.5;
  9. var halfHeight = graphics.height * Atomic.PIXEL_SIZE * 0.5;
  10. var enableDebugHud = false;
  11. function Start() {
  12. if (enableDebugHud) {
  13. var uiStyle = cache.getResource("XMLFile", "UI/DefaultStyle.xml");
  14. var debugHud = engine.createDebugHud();
  15. debugHud.defaultStyle = uiStyle;
  16. debugHud.toggleAll();
  17. }
  18. CreateScene();
  19. }
  20. function Update() {
  21. // physicsWorld.drawDebugGeometry();
  22. }
  23. function CreateScene() {
  24. daytime = true;
  25. scene = new Atomic.Scene();
  26. scene.createComponent("Octree");
  27. scene.createComponent("DebugRenderer");
  28. physicsWorld = scene.createComponent("PhysicsWorld2D");
  29. physicsWorld.continuousPhysics = false;
  30. physicsWorld.subStepping = false;
  31. cameraNode = scene.createChild("Camera");
  32. cameraNode.position = [0.0, 0.0, -10.0];
  33. camera = cameraNode.createComponent("Camera");
  34. camera.orthographic = true;
  35. camera.orthoSize = graphics.height * Atomic.PIXEL_SIZE;
  36. var viewport = new Atomic.Viewport(scene, camera);
  37. renderer.setViewport(0, viewport);
  38. // currently lightgroup must be created after viewport 0 is set
  39. lightGroupNode = scene.createChild("LightGroup");
  40. lightGroup = lightGroupNode.createComponent("Light2DGroup");
  41. lightGroup.setPhysicsWorld(physicsWorld);
  42. if (daytime)
  43. lightGroup.ambientColor = [1, 1, 1, .9];
  44. else
  45. lightGroup.ambientColor = [.8, .8, .8, .5];
  46. if (daytime)
  47. {
  48. TheSun = scene.createComponent("DirectionalLight2D");
  49. TheSun.color = [1, 1, 1, 0.15];
  50. TheSun.castShadows = true;
  51. TheSun.softShadows = true;
  52. TheSun.softShadowLength = 20;
  53. TheSun.numRays = 1024;
  54. TheSun.backtrace = false;
  55. lightGroup.addLight(TheSun);
  56. }
  57. uiNode = scene.createChild("UI");
  58. uiNode.createJSComponent("UI");
  59. levelNode = scene.createChild("Level");
  60. levelNode.createJSComponent("Level");
  61. avatarNode = scene.createChild("Avatar");
  62. avatarNode.createJSComponent("Avatar");
  63. backgroundNode = scene.createChild("Background");
  64. backgroundNode .createJSComponent("Background");
  65. }