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

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