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

100 lines
3.3 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/play.hpp"
  20. #include "entity/archetype.hpp"
  21. #include "entity/commands.hpp"
  22. #include "entity/components/observer.hpp"
  23. #include "entity/components/camera-follow.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 play {
  34. void enter(game::context* ctx)
  35. {
  36. // Find planet EID by name
  37. entity::id planet_eid = entt::null;
  38. if (auto it = ctx->named_entities.find("planet"); it != ctx->named_entities.end())
  39. {
  40. planet_eid = it->second;
  41. }
  42. // Create observer
  43. auto observer_eid = ctx->entity_registry->create();
  44. {
  45. entity::component::observer observer;
  46. observer.reference_body_eid = planet_eid;
  47. observer.elevation = 0.0;
  48. observer.latitude = 0.0;
  49. observer.longitude = 0.0;
  50. observer.camera = ctx->overworld_camera;
  51. ctx->entity_registry->assign<entity::component::observer>(observer_eid, observer);
  52. // Set reference location of astronomy system
  53. ctx->astronomy_system->set_reference_body(planet_eid);
  54. ctx->astronomy_system->set_observer_location(double3{observer.elevation, observer.latitude, observer.longitude});
  55. }
  56. // Create camera focal point
  57. {
  58. entity::component::transform focal_point_transform;
  59. focal_point_transform.local = math::identity_transform<float>;
  60. focal_point_transform.warp = true;
  61. ctx->entity_registry->assign_or_replace<entity::component::transform>(ctx->focal_point_entity, focal_point_transform);
  62. entity::component::camera_follow focal_point_follow;
  63. ctx->entity_registry->assign_or_replace<entity::component::camera_follow>(ctx->focal_point_entity, focal_point_follow);
  64. }
  65. // Setup camera
  66. ctx->overworld_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
  67. ctx->overworld_camera->set_exposure(-14.5f);
  68. ctx->camera_system->set_camera(ctx->overworld_camera);
  69. entity::system::control* control_system = ctx->control_system;
  70. control_system->update(0.0, 0.0);
  71. control_system->set_nest(nullptr);
  72. // Create larva
  73. {
  74. entity::archetype* larva_archetype = ctx->resource_manager->load<entity::archetype>("ant-larva.ent");
  75. auto larva_eid = larva_archetype->create(*ctx->entity_registry);
  76. entity::command::warp_to(*ctx->entity_registry, larva_eid, {50, 0.1935f, 0});
  77. }
  78. ctx->overworld_scene->update_tweens();
  79. // Start fade in
  80. ctx->fade_transition->transition(1.0f, true, ease<float>::in_quad);
  81. }
  82. void exit(game::context* ctx)
  83. {}
  84. } // namespace play
  85. } // namespace state
  86. } // namespace game