LetterHuntDialogue.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. class LetterHuntDialogue extends Object2D
  2. {
  3. /** @type {String} */
  4. text = ``;
  5. /** @type {Number} */
  6. bgOpacity = 0;
  7. /** @type {Number} */
  8. textOpacity = 0;
  9. /** @type {Button} */
  10. continueButton = null;
  11. /** @type {Tween} */
  12. tween = null;
  13. /** @type {Timer} */
  14. buttonTimer = null;
  15. _initSignals()
  16. {
  17. this.addSignal("dialogueFinished");
  18. }
  19. _setup()
  20. {
  21. this.text = `ACABOU O JOGO!\nVOCÊ GANHOU ${this.parent.points} PONTOS!`;
  22. this.setPosition(1920 / 2, 1080 - 300);
  23. this.continueButton = new Button("Continue", "Continuar")
  24. this.continueButton.setFontSize(40)
  25. this.continueButton.setPosition(-this.continueButton.getSize().x / 2, -this.continueButton.getSize().y / 2 + 100);
  26. this.continueButton.connect("mouseClicked", this, "_onContinueClicked");
  27. this.continueButton.hide();
  28. this.addChild(this.continueButton);
  29. this.tween = new Tween("Tween");
  30. this.tween.interpolateProperty(this, "bgOpacity", PROPERTY_TYPE.NUMBER, 0, 200, 2, TRANS_TYPE.LINEAR);
  31. this.tween.interpolateProperty(this, "textOpacity", PROPERTY_TYPE.NUMBER, 0, 255, 2, TRANS_TYPE.LINEAR);
  32. this.addChild(this.tween);
  33. this.buttonTimer = new Timer("ButtonTimer");
  34. this.buttonTimer.connect("timeout", this, "_onTimerTimeout");
  35. this.addChild(this.buttonTimer);
  36. }
  37. _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
  38. {
  39. db.noStroke();
  40. db.fill(0, this.bgOpacity);
  41. db.rectMode(CENTER);
  42. db.rect(0, 0, 1800, 400, 40, 40);
  43. db.textAlign(CENTER, CENTER);
  44. db.fill(255, this.textOpacity);
  45. db.textSize(40);
  46. db.text(this.text, 0, -100);
  47. }
  48. _initDialogue()
  49. {
  50. this.tween.startAll();
  51. this.buttonTimer.start(3);
  52. }
  53. _onTimerTimeout()
  54. {
  55. this.continueButton.show();
  56. }
  57. _onContinueClicked()
  58. {
  59. this.continueButton.hide();
  60. this.emitSignal("dialogueFinished");
  61. }
  62. }