main.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // This script is the main entry point of the game
  2. // create the start ui programmatically, we could also
  3. // use a ui template
  4. //create main view
  5. var view = new Atomic.UIView();
  6. //create a window
  7. var window = new Atomic.UIWindow();
  8. //disable tile bard and make it non resizeable
  9. window.settings = Atomic.UI_WINDOW_SETTINGS_TITLEBAR;
  10. window.text = "Physics Platformer";
  11. // Create a layout, otherwise child widgets won't know how to size themselves
  12. // and would manually need to be sized
  13. var layout = new Atomic.UILayout();
  14. layout.rect = view.rect;
  15. // give ourselves a little more spacing
  16. layout.spacing = 18;
  17. //axis to y
  18. layout.axis = Atomic.UI_AXIS_Y;
  19. //add ours layout to window
  20. window.addChild(layout);
  21. //create a text field
  22. var text = new Atomic.UITextField();
  23. text.text = "Please select the time of day:";
  24. layout.addChild(text);
  25. // Buttons layout
  26. var buttonLayout = new Atomic.UILayout();
  27. buttonLayout.axis = Atomic.UI_AXIS_X;
  28. layout.addChild(buttonLayout);
  29. var buttonDaytime = new Atomic.UIButton();
  30. buttonDaytime.text = "Play Daytime";
  31. buttonDaytime.onClick = function () {
  32. run(true);
  33. //we need to return value here, otherwise we will be GC'ed
  34. return true;
  35. }
  36. buttonLayout.addChild(buttonDaytime);
  37. var buttonNightTime = new Atomic.UIButton();
  38. buttonNightTime.text = "Play Nighttime";
  39. buttonNightTime.onClick = function () {
  40. run(false);
  41. //we need to return value here, otherwise we will be GC'ed
  42. return true;
  43. }
  44. buttonLayout.addChild(buttonNightTime);
  45. window.resizeToFitContent();
  46. // add to the root view and center
  47. view.addChild(window);
  48. window.center();
  49. var dayTime;
  50. function run(daytime) {
  51. //ok, then remove ours window
  52. view.removeChild(window);
  53. //require GlobalVariables module, and set its dayTime value to the current daytime
  54. require("GlobalVariables").dayTime = daytime;
  55. //load main scene!
  56. Atomic.player.loadScene("Scenes/Scene.scene");
  57. }