Game.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. require('MainMenu');
  2. require('World');
  3. class Game {
  4. constructor() {
  5. this.container = null;
  6. this.theater = null;
  7. this.canvas = null;
  8. this.system = null;
  9. this.state = "mainmenu";
  10. this.stage = null;
  11. this.stages = [];
  12. }
  13. init(system, container, canvas) {
  14. this.system = system;
  15. this.container = container;
  16. this.canvas = canvas;
  17. this.theater = this;
  18. this.stages.push(new MainMenu());
  19. this.stages.push(new World());
  20. this.changeStage("mainmenu");
  21. }
  22. changeStage(newstage) {
  23. if (this.stage != null && this.stage.end) {
  24. this.stage.end();
  25. }
  26. this.state = newstage;
  27. switch (this.state) {
  28. case "mainmenu":
  29. this.stage = this.stages[0];
  30. break;
  31. case "world":
  32. this.stage = this.stages[1];
  33. break;
  34. }
  35. this.stage.init(this.system, this.canvas);
  36. }
  37. updateDelta(delta, canvas) {
  38. this.stage.updateDelta(delta, canvas);
  39. }
  40. draw(context) {
  41. this.stage.draw(context);
  42. }
  43. handleResize(canvas) {
  44. if (!this.stage.hasOwnProperty("handleResize")) { return; }
  45. this.stage.handleResize(canvas);
  46. }
  47. };