main.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // This script is the main entry point of the game
  2. require("AtomicGame");
  3. Light2DExample = {};
  4. Atomic.game.init(start, update);
  5. // called at the start of play
  6. function start() {
  7. var game = Atomic.game;
  8. Light2DExample.halfWidth = game.graphics.width * Atomic.PIXEL_SIZE * 0.5;
  9. Light2DExample.halfHeight = game.graphics.height * Atomic.PIXEL_SIZE * 0.5;
  10. // create a 2D scene
  11. game.createScene2D();
  12. var scene = game.scene;
  13. var physicsWorld = scene.createComponent("PhysicsWorld2D");
  14. physicsWorld.continuousPhysics = false;
  15. physicsWorld.subStepping = false;
  16. var lightGroupNode = scene.createChild("LightGroup");
  17. var lightGroup = lightGroupNode.createComponent("Light2DGroup");
  18. lightGroup.setPhysicsWorld(physicsWorld);
  19. lightGroup.ambientColor = [.8, .8, .8, .5];
  20. Light2DExample.lightGroup = lightGroup;
  21. var node = game.scene.createChild();
  22. node.createJSComponent("Background");
  23. node.createJSComponent("Physics");
  24. for (var i = 0; i < 4; i++) {
  25. var lightNode = scene.createChild("LightNode");
  26. lightNode.createJSComponent("Light");
  27. }
  28. for (var i = 0; i < 16; i++) {
  29. var shadowCasterNode = scene.createChild("ShadowCaster");
  30. shadowCasterNode.createJSComponent("ShadowCaster");
  31. }
  32. }
  33. // called per frame
  34. function update(timeStep) {
  35. physicsWorld.drawDebugGeometry();
  36. }