FoodHuntDialogue.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. class FoodHuntDialogue extends Object2D
  2. {
  3. /** @type {String} */
  4. text1 = "Você conhece alguma árvore que dá tanto frutos diferentes assim?";
  5. /** @type {String} */
  6. text2 = " Já ouviu falar na grande árvore do Tamoromu? Converse com sua professora."
  7. /** @type {Number} */
  8. bgOpacity = 0;
  9. /** @type {Number} */
  10. text1Opacity = 0;
  11. /** @type {Number} */
  12. text2Opacity = 0;
  13. /** @type {Button} */
  14. continueButton = null;
  15. /** @type {Tween} */
  16. tween = null;
  17. /** @type {Timer} */
  18. buttonTimer = null;
  19. _initSignals()
  20. {
  21. this.addSignal("dialogueFinished");
  22. }
  23. _setup()
  24. {
  25. this.setPosition(1920 / 2, 1080 - 300);
  26. this.continueButton = new Button("Continue", "Continuar")
  27. this.continueButton.setFontSize(40)
  28. this.continueButton.setPosition(-this.continueButton.getSize().x / 2, -this.continueButton.getSize().y / 2 + 100);
  29. this.continueButton.connect("mouseClicked", this, "_onContinueClicked");
  30. this.continueButton.hide();
  31. this.addChild(this.continueButton);
  32. this.tween = new Tween("Tween");
  33. this.tween.interpolateProperty(this, "bgOpacity", PROPERTY_TYPE.NUMBER, 0, 200, 2, TRANS_TYPE.LINEAR);
  34. this.tween.interpolateProperty(this, "text1Opacity", PROPERTY_TYPE.NUMBER, 0, 255, 2, TRANS_TYPE.LINEAR);
  35. this.tween.interpolateProperty(this, "text2Opacity", PROPERTY_TYPE.NUMBER, 0, 255, 2, TRANS_TYPE.LINEAR, EASE_TYPE.IN, 3);
  36. this.addChild(this.tween);
  37. this.buttonTimer = new Timer("ButtonTimer");
  38. this.buttonTimer.connect("timeout", this, "_onTimerTimeout");
  39. this.addChild(this.buttonTimer);
  40. }
  41. _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
  42. {
  43. db.noStroke();
  44. db.fill(0, this.bgOpacity);
  45. db.rectMode(CENTER);
  46. db.rect(0, 0, 1800, 400, 40, 40);
  47. db.textAlign(CENTER, CENTER);
  48. db.fill(255, this.text1Opacity);
  49. db.textSize(40);
  50. db.text(this.text1, 0, -100);
  51. db.fill(255, this.text2Opacity);
  52. db.text(this.text2, 0, 0);
  53. }
  54. _initDialogue()
  55. {
  56. this.tween.startAll();
  57. this.buttonTimer.start(5);
  58. }
  59. _onTimerTimeout()
  60. {
  61. this.continueButton.show();
  62. }
  63. _onContinueClicked()
  64. {
  65. this.continueButton.hide();
  66. this.emitSignal("dialogueFinished");
  67. }
  68. }