123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- require('MainMenu');
- require('World');
- class Game {
- constructor() {
- this.container = null;
- this.theater = null;
- this.canvas = null;
- this.system = null;
- this.state = "mainmenu";
- this.stage = null;
- this.stages = [];
- }
- init(system, container, canvas) {
- this.system = system;
- this.container = container;
- this.canvas = canvas;
- this.theater = this;
- this.stages.push(new MainMenu());
- this.stages.push(new World());
- this.changeStage("mainmenu");
- }
- changeStage(newstage) {
- if (this.stage != null && this.stage.end) {
- this.stage.end();
- }
- this.state = newstage;
- switch (this.state) {
- case "mainmenu":
- this.stage = this.stages[0];
- break;
- case "world":
- this.stage = this.stages[1];
- break;
- }
- this.stage.init(this.system, this.canvas);
- }
- updateDelta(delta, canvas) {
- this.stage.updateDelta(delta, canvas);
- }
- draw(context) {
- this.stage.draw(context);
- }
- handleResize(canvas) {
- if (!this.stage.hasOwnProperty("handleResize")) { return; }
- this.stage.handleResize(canvas);
- }
- };
|