mainmenu.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. include("mouseinput.js");
  2. include("curtain.js");
  3. include("button.js");
  4. function MainMenu(game, camera) {
  5. this.system = null;
  6. this.canvas = null;
  7. this.keyboard = null;
  8. this.mouse = null;
  9. this.curtain = null;
  10. this.playButton = null;
  11. this.textMetrics = null;
  12. this.init = function(systemObject, canvas) {
  13. var stage = this;
  14. this.system = systemObject;
  15. this.canvas = canvas;
  16. this.mouse = new MouseInput();
  17. this.mouse.attach(canvas, this);
  18. this.curtain = new Curtain();
  19. this.curtain.init(systemObject, canvas);
  20. this.curtain.open(700, function() {
  21. stage.isStarted = true;
  22. });
  23. this.playButton = new Button(canvas);
  24. this.playButton.addClickEvent(this.joinGame);
  25. this.handleResize(canvas);
  26. };
  27. this.handleResize = function(canvas) {
  28. var buttonOptions = {position: {x: this.canvas.width / 2, y: this.canvas.height / 2}, font:{color:"#DDDDDD", stroke: "#333333", size: 72, family: "sans-serif"}};
  29. if(this.canvas.width < 768) {
  30. buttonOptions.font.size = 36;
  31. }
  32. this.playButton.init("Start", buttonOptions);
  33. }
  34. this.end = function(callback) {
  35. this.mouse.detatch();
  36. this.closeCurtain(callback);
  37. }
  38. this.closeCurtain = function(callback) {
  39. system.theater.stage.curtain.close(700, function() {
  40. callback();
  41. });
  42. }
  43. this.joinGame = function() {
  44. system.theater.changeStage("slotmachine");
  45. }
  46. this.updateDelta = function(delta, canvas) {
  47. if(system.keyboard.isPressed(Keys.Space) || system.keyboard.isPressed(Keys.Enter)) {
  48. this.joinGame();
  49. }
  50. this.curtain.updateDelta(delta);
  51. };
  52. this.draw = function(context) {
  53. var title = "Trash Slots";
  54. context.font = "72px sans-serif";
  55. context.textAlign = "center";
  56. context.textBaseline = "middle";
  57. var textWidth = context.measureText(title).width;
  58. context.fillStyle = "#DDDDDD";
  59. context.strokeStyle = "#333333";
  60. context.lineWidth = 2;
  61. if(this.canvas.width < 768) {
  62. context.font = "36px sans-serif";
  63. }
  64. context.fillText(title, this.canvas.width /2 , 100);
  65. this.playButton.draw(context);
  66. this.curtain.draw(context);
  67. };
  68. this.mouseMove = function(canvas, x, y) {
  69. this.playButton.mouseMove(x, y);
  70. }
  71. this.touchMove = function(canvas, x, y) {
  72. this.playButton.touchMove(x, y);
  73. }
  74. this.mouseDown = function(canvas, button, x, y) {
  75. this.playButton.mouseDown(button, x, y);
  76. }
  77. this.touchStart = function(canvas, x, y) {
  78. this.playButton.touchStart(x, y);
  79. };
  80. };