Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. var GameScreen = function(assetManager, stage) {
  2. // On this screen the player has exactly five seconds to beat the clock
  3. "use strict";
  4. // custom event for next button
  5. var eventScreenComplete = new createjs.Event("playFinished");
  6. var eventScreenPrevious = new createjs.Event("playPrevious");
  7. // construct container to hold all sprites of screen
  8. var screen = new createjs.Container();
  9. // add background to screen
  10. var background = assetManager.getSprite("uiAssets");
  11. background.gotoAndStop("gameScreen");
  12. screen.addChild(background);
  13. // construct hitspot sprite
  14.  
  15.  
  16. // timer variables
  17. var timer = null;
  18. var countDown = 60;
  19. var txtTimer = null;
  20.  
  21.  
  22. // ------------------------------------------------------------ private methods
  23. function startTimer() {
  24. timer = window.setInterval(onTimerUpdate, 1000);
  25. }
  26.  
  27. function stopTimer() {
  28. window.clearInterval(timer);
  29. countDown = 60;
  30. timer = null;
  31. }
  32.  
  33.  
  34. function onTimerUpdate(e) {
  35. //console.log("time!");
  36. countDown--;
  37. txtTimer.text = String(countDown);
  38. // detect if game over
  39. if (countDown == 0) {
  40. userGuess = "";
  41. stopTimer();
  42. } else if (countDown <= 10) {
  43. createjs.Sound.play("timeSound");
  44. }
  45. }
  46.  
  47.  
  48.  
  49. var hitAreaSprite = assetManager.getSprite("uiAssets");
  50. var ghosts = [],
  51. ghostMover = [],
  52. numberOfGhosts = 12, // Not needed? See comment below.
  53. index = 0,
  54. clearedGhosts = [];
  55.  
  56.  
  57.  
  58. // add quit button
  59. var btnQuit = assetManager.getSprite("uiAssets");
  60. btnQuit.gotoAndStop("previousUp");
  61. btnQuit.x = 40;
  62. btnQuit.y = 260;
  63. btnQuit.buttonHelper = new createjs.ButtonHelper(btnQuit, "quitUp", "quitOver", "quitOver", false, hitAreaSprite, "hitArea");
  64. btnQuit.addEventListener("click",onQuit);
  65. screen.addChild(btnQuit);
  66.  
  67. /*
  68. This function will add a new sprite to the screen at the given coordinate and place the needed data in the arrays.
  69. */
  70.  
  71. function addSprite(x, y) {
  72. "use strict";
  73. var ghostIndex = ghosts.length;
  74. ghosts[ghostIndex] = assetManager.getSprite("uiAssets");
  75. ghostMover[ghostIndex] = new Mover(ghosts[ghostIndex], stage, ghostIndex, clearedGhosts, numberOfGhosts);
  76. ghosts[ghostIndex].x = x;
  77. ghosts[ghostIndex].y = y;
  78. ghosts[ghostIndex].gotoAndStop("ghostAlive");
  79. screen.addChild(ghosts[ghostIndex]);
  80. ghostMover[ghostIndex].startMe();
  81. }
  82. addSprite(10, 10); // Index 0.
  83. addSprite(80, 10); // Index 1.
  84. addSprite(150, 10); // Index 2.
  85. addSprite(220, 10); // Index 3.
  86. addSprite(10, 80); // Index 4.
  87. addSprite(80, 80); // Index 5.
  88. addSprite(150, 80); // Index 6.
  89. addSprite(220, 80); // Index 7.
  90. addSprite(10, 150); // Index 8.
  91. addSprite(80, 150); // Index 9.
  92. addSprite(150, 150); // Index 10.
  93. addSprite(220, 150); // Index 11.
  94. /*
  95. * I'm not sure if the above is correct.
  96. * You was over-writing the sprites each row? You wasn't creating a new sprite for each row.
  97. */
  98.  
  99.  
  100. function onQuit(e){
  101. console.log("clicked on prev!");
  102. // telling the world the prev button has been clicked!
  103. stage.dispatchEvent(eventScreenPrevious);
  104. }
  105.  
  106. function onPlay(e){
  107. console.log("Play has started!");
  108. }
  109.  
  110. // ---------------------------------- public methods
  111. this.showMe = function() {
  112. // anything else that needs to be done when the screen is shown
  113. // ...
  114. stage.addChild(screen);
  115. //stage.addChild(ghost1)
  116. }
  117. this.hideMe = function() {
  118. stage.removeChild(screen);
  119.  
  120. }
  121. function onTick(e) {
  122. ghostMover1.updateMe();
  123. // update the stage!
  124. stage.update();
  125. }
  126. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement