2018js13kgame.js 1.0 KB

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