FoodHuntDialogue.js 2.5 KB

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