endgame.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. include("mouseinput.js");
  2. include("curtain.js");
  3. include("button.js");
  4. function EndGame(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.showError = false;
  26. this.handleResize(canvas);
  27. };
  28. this.handleResize = function(canvas) {
  29. var buttonOptions = {position: {x: this.canvas.width / 2, y: this.canvas.height / 2}, font:{color:"#DDDDDD", stroke: "#333333", size: 72, family: "sans-serif"}};
  30. if(this.canvas.width < 768) {
  31. buttonOptions.font.size = 36;
  32. }
  33. this.playButton.init("Main Menu", buttonOptions);
  34. }
  35. this.end = function(callback) {
  36. this.mouse.detatch();
  37. this.closeCurtain(callback);
  38. }
  39. this.closeCurtain = function(callback) {
  40. system.theater.stage.curtain.close(700, function() {
  41. callback();
  42. });
  43. }
  44. this.joinGame = function() {
  45. system.theater.changeStage("mainmenu");
  46. }
  47. this.updateDelta = function(delta, canvas) {
  48. if(system.keyboard.isPressed(Keys.Space) || system.keyboard.isPressed(Keys.Enter)) {
  49. this.joinGame();
  50. }
  51. this.curtain.updateDelta(delta);
  52. };
  53. this.draw = function(context) {
  54. var title = "You Win!";
  55. context.font = "72px sans-serif";
  56. context.textAlign = "center";
  57. context.textBaseline = "middle";
  58. var textWidth = context.measureText(title).width;
  59. context.fillStyle = "#DDDDDD";
  60. context.strokeStyle = "#333333";
  61. context.lineWidth = 2;
  62. if(this.canvas.width < 768) {
  63. context.font = "36px sans-serif";
  64. }
  65. context.fillText(title, this.canvas.width /2 , 100);
  66. var prizeAmount = "$" + system.theater.stages["slotmachine"].prize;
  67. context.font = "36px sans-serif";
  68. context.textAlign = "center";
  69. context.textBaseline = "middle";
  70. context.fillStyle = "#DDDDDD";
  71. context.strokeStyle = "#333333";
  72. context.lineWidth = 2;
  73. if(this.canvas.width < 768) {
  74. context.font = "16px sans-serif";
  75. }
  76. context.fillText(prizeAmount, this.canvas.width /2, 200);
  77. this.playButton.draw(context);
  78. this.curtain.draw(context);
  79. };
  80. this.mouseMove = function(canvas, x, y) {
  81. this.playButton.mouseMove(x, y);
  82. }
  83. this.touchMove = function(canvas, x, y) {
  84. this.playButton.touchMove(x, y);
  85. }
  86. this.mouseDown = function(canvas, button, x, y) {
  87. this.playButton.mouseDown(button, x, y);
  88. }
  89. this.touchStart = function(canvas, x, y) {
  90. this.playButton.touchStart(x, y);
  91. };
  92. };