AcrofonyGameDialogue.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /************************************************************************
  2. * AcrofonyGameDialogue.js
  3. ************************************************************************
  4. * Copyright (c) 2021 Pedro Tonini Rosenberg Schneider.
  5. *
  6. * This file is part of Alfabetiza.
  7. *
  8. * Alfabetiza is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Alfabetiza is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Alfabetiza. If not, see <https://www.gnu.org/licenses/>.
  20. *************************************************************************/
  21. class AcrofonyGameDialogue extends Object2D
  22. {
  23. constructor(name)
  24. {
  25. super(name);
  26. /** @type {Button} */
  27. this.continueButton = null;
  28. /** @type {Timer} */
  29. this.timer;
  30. /** @type {String} */
  31. this.suffix = "";
  32. /** @type {number} */
  33. this.bgOpacity = 0;
  34. /** @type {number} */
  35. this.textOpacity = 0;
  36. }
  37. _initSignals()
  38. {
  39. this.addSignal("endGame");
  40. }
  41. _setup()
  42. {
  43. this.timer = new Timer("Timer", 2, false, true);
  44. this.timer.connect("timeout", this, "_onTimerTimeout");
  45. this.addChild(this.timer);
  46. this.continueButton = new Button("ContinueButton", "Continuar");
  47. this.continueButton.setFontSize(40);
  48. this.continueButton.setPosition(1920 / 2 - this.continueButton.getSize().x / 2, 600);
  49. this.continueButton.connect("mouseClicked", this, "_onContinueButtonClicked");
  50. this.addChild(this.continueButton);
  51. this.continueButton.hide();
  52. }
  53. _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
  54. {
  55. if (this.parent.gameFinished)
  56. {
  57. this.timer.start();
  58. db.noStroke();
  59. db.fill(0, min(this.bgOpacity += 75 * delta, 200));
  60. db.rectMode(CENTER);
  61. db.rect(db.width / 2, db.height / 2, 1800, 600, 40, 40);
  62. db.textAlign(CENTER, CENTER);
  63. db.fill(255, min(this.textOpacity += 80 * delta, 255));
  64. db.textSize(40);
  65. this.parent.points > 1 ? this.suffix = "S" : this.suffix = "";
  66. db.text(`PARABÉNS, NÍVEL CONCLUÍDO\n\nVOCÊ GANHOU ${this.parent.points} PONTO${this.suffix}!`, db.width / 2, db.height / 2 - 100);
  67. }
  68. }
  69. _onTimerTimeout()
  70. {
  71. this.continueButton.show();
  72. }
  73. _onContinueButtonClicked()
  74. {
  75. this.emitSignal("endGame");
  76. }
  77. }