trashslots.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. include("system.js");
  2. include("mainmenu.js");
  3. include("slotmachine.js");
  4. include("endgame.js");
  5. function TrashSlots() {
  6. var theater = null;
  7. this.theater = null;
  8. this.canvas = null;
  9. this.system = null;
  10. this.state = "";
  11. this.stage = null;
  12. this.stages = {};
  13. this.init = function(systemObject, canvas) {
  14. this.theater = this;
  15. theater = this;
  16. this.system = systemObject;
  17. this.canvas = canvas;
  18. this.stages["mainmenu"] = new MainMenu();
  19. this.stages["slotmachine"] = new SlotMachine();
  20. this.stages["end"] = new EndGame();
  21. this.changeStage("mainmenu");
  22. };
  23. this.loadAssets = function(callback) {
  24. var assetFiles = {
  25. "slotreel": "./images/slotreel.png"
  26. };
  27. system.assets.load(assetFiles, callback);
  28. }
  29. this.changeStage = function(newstage) {
  30. if(this.state == newstage) {
  31. return;
  32. }
  33. if(this.stage != null && this.stage.hasOwnProperty("end")) {
  34. this.stage.end(function() {
  35. theater.state = newstage;
  36. theater.stage = theater.stages[theater.state];
  37. theater.stage.init(theater.system, theater.canvas);
  38. });
  39. } else {
  40. theater.state = newstage;
  41. theater.stage = theater.stages[theater.state];
  42. theater.stage.init(theater.system, theater.canvas);
  43. }
  44. }
  45. this.updateDelta = function(delta, canvas){
  46. this.stage.updateDelta(delta, canvas);
  47. };
  48. this.draw = function(context) {
  49. this.stage.draw(context);
  50. };
  51. this.handleResize = function(canvas) {
  52. if(!this.stage.hasOwnProperty("handleResize")) { return; }
  53. this.stage.handleResize(canvas);
  54. };
  55. };
  56. TrashSlots.attach = function(domContainer, backgroundColor) {
  57. loader.finishedLoading(function() {
  58. window.system = new System();
  59. system.create(domContainer, new TrashSlots(), backgroundColor);
  60. });
  61. }