Valise2LevelSelector.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /************************************************************************
  2. * Valise2LevelSelector.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 Valise2LevelSelector extends Object2D
  22. {
  23. constructor(name)
  24. {
  25. super(name);
  26. /** @type {Object} */
  27. this.gridMargins = {
  28. left: 0,
  29. right: 0,
  30. up: 500,
  31. down: 0
  32. };
  33. /** @type {number} */
  34. this.gridCols = 4;
  35. }
  36. _setup()
  37. {
  38. var b = new RebusLevelButton("Tutorial");
  39. b.levelData = VALISE2_LEVELS.tutorial;
  40. b.setLabel("Tutorial");
  41. b.setFontSize(40);
  42. this.addChild(b);
  43. b.setSize(200, 100);
  44. b.setPosition((1920 - b.getSize().x) / 2, 300);
  45. b.connect("levelSelected", this, "_onTutorialSelected");
  46. var i = 1;
  47. while (VALISE2_LEVELS[`level${i}`])
  48. {
  49. var b = new Valise2LevelButton(`level${i}`);
  50. b.levelData = VALISE2_LEVELS[`level${i}`];
  51. b.setLabel(`${i}`);
  52. b.setFontSize(40);
  53. this.addChild(b);
  54. b.setSize(100, 100);
  55. b.setPosition((((i - 1) % this.gridCols) + 1) * 1920 / (this.gridCols + 1) - b.getSize().x / 2, this.gridMargins.up + 200 * int((i - 1) / this.gridCols));
  56. b.connect("levelSelected", this, "_onLevelSelected");
  57. i++;
  58. }
  59. this.backButton = new Button("BackButton");
  60. this.backButton.setLabel("Voltar");
  61. this.backButton.setFontSize(30);
  62. this.backButton.setPosition(20, 20);
  63. this.backButton.setSize(110, 75);
  64. this.backButton.connect("mouseClicked", this, "_onBackClicked");
  65. this.addChild(this.backButton);
  66. }
  67. _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
  68. {
  69. background(52);
  70. db.textAlign(CENTER, CENTER);
  71. db.fill(255);
  72. db.textSize(100);
  73. db.text("PALAVRA VALISE 2", 1920 / 2, 125);
  74. db.textSize(40);
  75. db.text("Escolha o nível", 1920 / 2, 200);
  76. }
  77. _onTutorialSelected( /** @type {Object} */ levelData)
  78. {
  79. var vt = new Valise2Tutorial("Valise2Tutorial");
  80. vt.levelData = levelData;
  81. GameHandler.addRootObject(vt);
  82. this.queueFree();
  83. }
  84. _onLevelSelected( /** @type {Object} */ levelData)
  85. {
  86. var vg = new Valise2Game("Valise2Game");
  87. vg.levelData = levelData;
  88. GameHandler.addRootObject(vg);
  89. this.queueFree();
  90. }
  91. _onBackClicked()
  92. {
  93. var ems = new EarthMinigameSelector("EarthMinigameSelector");
  94. GameHandler.addRootObject(ems);
  95. this.queueFree();
  96. }
  97. }