💿🐜 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.

103 lines
3.5 KiB

  1. /*
  2. * Copyright (C) 2021 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 "game/states/forage.hpp"
  20. #include "entity/archetype.hpp"
  21. #include "entity/commands.hpp"
  22. #include "entity/components/observer.hpp"
  23. #include "entity/components/terrain.hpp"
  24. #include "entity/components/transform.hpp"
  25. #include "entity/systems/astronomy.hpp"
  26. #include "animation/screen-transition.hpp"
  27. #include "animation/ease.hpp"
  28. #include "resources/resource-manager.hpp"
  29. namespace game {
  30. namespace state {
  31. namespace forage {
  32. void enter(game::context* ctx)
  33. {
  34. // Switch to surface camera
  35. ctx->underground_camera->set_active(false);
  36. ctx->surface_camera->set_active(true);
  37. // Find planet EID by name
  38. entity::id planet_eid = ctx->entities["planet"];
  39. // Create biome terrain component
  40. entity::component::terrain biome_terrain;
  41. biome_terrain.max_lod = 18;
  42. biome_terrain.patch_material = ctx->resource_manager->load<material>("desert-terrain.mtl");
  43. biome_terrain.elevation = [](double, double) -> double
  44. {
  45. return 0.0;
  46. };
  47. // Replace planet terrain component with biome terrain component
  48. ctx->entity_registry->replace<entity::component::terrain>(planet_eid, biome_terrain);
  49. // Create observer
  50. entity::id observer_eid = ctx->entity_registry->create();
  51. {
  52. entity::component::observer observer;
  53. observer.reference_body_eid = planet_eid;
  54. observer.elevation = 0.0;
  55. observer.latitude = 0.0;
  56. observer.longitude = 0.0;
  57. observer.camera = ctx->surface_camera;
  58. ctx->entity_registry->assign<entity::component::observer>(observer_eid, observer);
  59. // Set reference location of astronomy system
  60. ctx->astronomy_system->set_reference_body(planet_eid);
  61. ctx->astronomy_system->set_observer_location(double3{observer.elevation, observer.latitude, observer.longitude});
  62. }
  63. // Setup camera
  64. ctx->surface_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
  65. ctx->surface_camera->set_exposure(-14.5f);
  66. // Create larva
  67. {
  68. entity::archetype* larva_archetype = ctx->resource_manager->load<entity::archetype>("ant-larva.ent");
  69. auto larva_eid = larva_archetype->create(*ctx->entity_registry);
  70. entity::command::warp_to(*ctx->entity_registry, larva_eid, {50, 0.1935f, 0});
  71. entity::command::assign_render_layers(*ctx->entity_registry, larva_eid, 0b10);
  72. }
  73. // Create cocoon
  74. {
  75. entity::archetype* cocoon_archetype = ctx->resource_manager->load<entity::archetype>("ant-cocoon.ent");
  76. auto cocoon_eid = cocoon_archetype->create(*ctx->entity_registry);
  77. entity::command::warp_to(*ctx->entity_registry, cocoon_eid, {-50, 0.1935f, 0});
  78. entity::command::assign_render_layers(*ctx->entity_registry, cocoon_eid, 0b10);
  79. }
  80. ctx->surface_scene->update_tweens();
  81. // Start fade in
  82. ctx->fade_transition->transition(1.0f, true, ease<float>::in_quad);
  83. }
  84. void exit(game::context* ctx)
  85. {}
  86. } // namespace forage
  87. } // namespace state
  88. } // namespace game