💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.9 KiB

  1. /*
  2. * Copyright (C) 2017 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper Source Code.
  5. *
  6. * Antkeeper Source Code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper Source Code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "level-select-state.hpp"
  20. #include "main-menu-state.hpp"
  21. #include "../application.hpp"
  22. #include "../configuration.hpp"
  23. #include "../camera-controller.hpp"
  24. LevelSelectState::LevelSelectState(Application* application):
  25. ApplicationState(application)
  26. {}
  27. LevelSelectState::~LevelSelectState()
  28. {}
  29. void LevelSelectState::enter()
  30. {
  31. levelRotation = 0.0f;
  32. for (int i = 0; i < 5; ++i)
  33. {
  34. ModelInstance* surfaceInstance = &application->previewLevelSurfaces[i];
  35. ModelInstance* subsurfaceInstance = &application->previewLevelSubsurfaces[i];
  36. Quaternion rotation = glm::angleAxis(levelRotation, Vector3(0, 1, 0));
  37. surfaceInstance->setRotation(rotation);
  38. subsurfaceInstance->setRotation(rotation);
  39. application->defaultLayer->addObject(surfaceInstance);
  40. application->defaultLayer->addObject(subsurfaceInstance);
  41. }
  42. application->defaultLayer->addObject(&application->biomeFloorModelInstance);
  43. application->levelIDLabel->setVisible(true);
  44. application->levelNameLabel->setVisible(true);
  45. application->selectWorld(0);
  46. application->selectLevel(0);
  47. // Setup camera controller
  48. application->surfaceCam->setTargetFocalPoint(Vector3(0.0f));
  49. application->surfaceCam->setTargetFocalDistance(350.0f);
  50. application->surfaceCam->setTargetElevation(glm::radians(85.0f));
  51. application->surfaceCam->setTargetAzimuth(0.0f);
  52. application->surfaceCam->update(0.0f);
  53. }
  54. void LevelSelectState::execute()
  55. {
  56. // Navigate menu
  57. if (application->menuLeft.isTriggered() && !application->menuLeft.wasTriggered())
  58. {
  59. application->selectPreviousLevel();
  60. }
  61. else if (application->menuRight.isTriggered() && !application->menuRight.wasTriggered())
  62. {
  63. application->selectNextLevel();
  64. }
  65. if (application->menuDown.isTriggered() && !application->menuDown.wasTriggered())
  66. {
  67. application->selectPreviousWorld();
  68. }
  69. else if (application->menuUp.isTriggered() && !application->menuUp.wasTriggered())
  70. {
  71. application->selectNextWorld();
  72. }
  73. if (application->menuSelect.isTriggered() && !application->menuSelect.wasTriggered())
  74. {
  75. application->enterSelectedLevel();
  76. }
  77. else if (application->menuCancel.isTriggered() && !application->menuCancel.wasTriggered())
  78. {
  79. application->changeState(application->mainMenuState);
  80. }
  81. // Rotate levels
  82. levelRotation += glm::radians(5.0f) * application->dt;
  83. for (int i = 0; i < 5; ++i)
  84. {
  85. ModelInstance* surfaceInstance = &application->previewLevelSurfaces[i];
  86. ModelInstance* subsurfaceInstance = &application->previewLevelSubsurfaces[i];
  87. Quaternion rotation = glm::angleAxis(levelRotation, Vector3(0, 1, 0));
  88. //surfaceInstance->setRotation(rotation);
  89. //subsurfaceInstance->setRotation(rotation);
  90. }
  91. // Update camera
  92. application->surfaceCam->update(application->dt);
  93. }
  94. void LevelSelectState::exit()
  95. {
  96. for (int i = 0; i < 5; ++i)
  97. {
  98. ModelInstance* surfaceInstance = &application->previewLevelSurfaces[i];
  99. ModelInstance* subsurfaceInstance = &application->previewLevelSubsurfaces[i];
  100. application->defaultLayer->removeObject(surfaceInstance);
  101. application->defaultLayer->removeObject(subsurfaceInstance);
  102. }
  103. application->defaultLayer->removeObject(&application->biomeFloorModelInstance);
  104. application->levelIDLabel->setVisible(false);
  105. application->levelNameLabel->setVisible(false);
  106. }