function Game() { this.theater = null; this.canvas = null; this.system = null; this.state = "mainmenu"; this.stage = null; this.stages = []; this.init = function(systemObject, canvas) { this.theater = this; this.system = systemObject; this.canvas = canvas; this.stages.push(new MainMenu()); this.stages.push(new World()); this.changeStage("mainmenu"); }; this.changeStage = function(newstage) { if(this.stage != null && this.stage.hasOwnProperty("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); } this.updateDelta = function(delta, canvas){ this.stage.updateDelta(delta, canvas); }; this.draw = function(context) { this.stage.draw(context); }; this.handleResize = function(canvas) { if(!this.stage.hasOwnProperty("handleResize")) { return; } this.stage.handleResize(canvas); } };