Valise1Tutorial.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. class Valise1Tutorial extends Object2D
  2. {
  3. constructor(name)
  4. {
  5. super(name);
  6. /** @type {Object} */
  7. this.levelData = null;
  8. /** @type {Valise1QuestionCard} */
  9. this.questionCard = null;
  10. /** @type {Object2D} */
  11. this.optionCards = null;
  12. /** @type {Button} */
  13. this.backButton = null;
  14. /** @type {Valise1TutorialDialogue} */
  15. this.dialogue = null;
  16. /** @type {Timer} */
  17. this.timer = null;
  18. /** @type {Number} */
  19. this.points = 3;
  20. /** @type {Boolean} */
  21. this.gameFinished = false;
  22. /** @type {Number} */
  23. this.tutorialStep = 0;
  24. }
  25. _setup()
  26. {
  27. this.backButton = new Button("BackButton");
  28. this.backButton.setLabel("Voltar");
  29. this.backButton.setFontSize(30);
  30. this.backButton.setPosition(20, 20);
  31. this.backButton.setSize(110, 75);
  32. this.backButton.connect("mouseClicked", this, "_onBackClicked");
  33. this.addChild(this.backButton);
  34. AssetHandler.loadTexture(this.levelData.questionCard.name, this.levelData.questionCard.path);
  35. this.questionCard = new Valise1QuestionCard("QuestionCard");
  36. this.questionCard.thumb = AssetHandler.getTextureByName(this.levelData.questionCard.name);
  37. this.questionCard.setPosition(1920 / 2, 300);
  38. this.addChild(this.questionCard);
  39. this.optionCards = new Object2D("OptionCards");
  40. this.addChild(this.optionCards);
  41. var idx = [0, 1, 2, 3];
  42. randomSeed(Date.now());
  43. idx = shuffle(idx);
  44. for (let i = 0; i < 4; i++)
  45. {
  46. AssetHandler.loadTexture(this.levelData.optionCards[idx[i]].name, this.levelData.optionCards[idx[i]].path);
  47. var newCard = new Valise1OptionCard(`OptionCard${i}`);
  48. newCard.thumb = AssetHandler.getTextureByName(this.levelData.optionCards[idx[i]].name);
  49. newCard.setPosition((i + 1) * 1920 / 5, 800);
  50. newCard.isAnswer = idx[i] == 0;
  51. newCard.connect("selected", this, "_onCardSelected");
  52. newCard.str = this.levelData.optionCards[idx[i]].name;
  53. newCard.selectable = false;
  54. this.optionCards.addChild(newCard);
  55. }
  56. this.dialogue = new Valise1TutorialDialogue("TutorialDialogue");
  57. this.dialogue.connect("continue", this, "_onTutorialContinue");
  58. this.addChild(this.dialogue);
  59. this.timer = new Timer("Timer", 2, false, true);
  60. this.timer.connect("timeout", this, "_onTimerTimeout");
  61. this.addChild(this.timer);
  62. this.timer.start();
  63. }
  64. _draw( /** @type {Number} */ delta, /** @type {p5.Graphics} */ db)
  65. {
  66. background(52);
  67. }
  68. _onCardSelected( /** @type {Boolean} */ isAnswer)
  69. {
  70. if (!isAnswer) this.points--;
  71. else
  72. {
  73. this.gameFinished = true;
  74. for (let i = 0; i < 4; i++)
  75. this.optionCards.children[i].selectable = false;
  76. }
  77. console.log(isAnswer);
  78. }
  79. _onTutorialContinue()
  80. {
  81. this.tutorialStep++;
  82. switch (this.tutorialStep)
  83. {
  84. case 2:
  85. this.timer.start(2);
  86. break;
  87. case 10:
  88. this._onBackClicked();
  89. break;
  90. }
  91. }
  92. _onTimerTimeout()
  93. {
  94. this.tutorialStep++;
  95. switch (this.tutorialStep)
  96. {
  97. case 3:
  98. this.optionCards.children[0].selectable = true;
  99. this.optionCards.children[0].mouseOver = true;
  100. this.optionCards.children[1].selectable = false;
  101. this.optionCards.children[1].mouseOver = false;
  102. this.optionCards.children[2].selectable = false;
  103. this.optionCards.children[2].mouseOver = false;
  104. this.optionCards.children[3].selectable = false;
  105. this.optionCards.children[3].mouseOver = false;
  106. this.timer.start(0.5);
  107. break;
  108. case 4:
  109. this.optionCards.children[0].selectable = false;
  110. this.optionCards.children[0].mouseOver = false;
  111. this.optionCards.children[1].selectable = true;
  112. this.optionCards.children[1].mouseOver = true;
  113. this.optionCards.children[2].selectable = false;
  114. this.optionCards.children[2].mouseOver = false;
  115. this.optionCards.children[3].selectable = false;
  116. this.optionCards.children[3].mouseOver = false;
  117. this.timer.start(0.5);
  118. break;
  119. case 5:
  120. this.optionCards.children[0].selectable = false;
  121. this.optionCards.children[0].mouseOver = false;
  122. this.optionCards.children[1].selectable = false;
  123. this.optionCards.children[1].mouseOver = false;
  124. this.optionCards.children[2].selectable = true;
  125. this.optionCards.children[2].mouseOver = true;
  126. this.optionCards.children[3].selectable = false;
  127. this.optionCards.children[3].mouseOver = false;
  128. this.timer.start(0.5);
  129. break;
  130. case 6:
  131. this.optionCards.children[0].selectable = false;
  132. this.optionCards.children[0].mouseOver = false;
  133. this.optionCards.children[1].selectable = false;
  134. this.optionCards.children[1].mouseOver = false;
  135. this.optionCards.children[2].selectable = false;
  136. this.optionCards.children[2].mouseOver = false;
  137. this.optionCards.children[3].selectable = true;
  138. this.optionCards.children[3].mouseOver = true;
  139. this.timer.start(0.5);
  140. break;
  141. case 7:
  142. this.optionCards.children[0].selectable = false;
  143. this.optionCards.children[0].mouseOver = false;
  144. this.optionCards.children[1].selectable = false;
  145. this.optionCards.children[1].mouseOver = false;
  146. this.optionCards.children[2].selectable = false;
  147. this.optionCards.children[2].mouseOver = false;
  148. this.optionCards.children[3].selectable = false;
  149. this.optionCards.children[3].mouseOver = false;
  150. this.timer.start(2);
  151. break;
  152. case 8:
  153. this.optionCards.children[0].selected = true;
  154. this.optionCards.children[1].selected = true;
  155. this.optionCards.children[2].selected = true;
  156. this.optionCards.children[3].selected = true;
  157. this.timer.start(1);
  158. break;
  159. }
  160. }
  161. _onBackClicked()
  162. {
  163. var vls = new Valise1LevelSelector("Valise1LevelSelector");
  164. GameHandler.addRootObject(vls);
  165. AssetHandler.clearTextureCache();
  166. this.queueFree();
  167. }
  168. }