A small game engine for 2D games based of Raylib
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

65 righe
2.3 KiB

  1. #include <iostream>
  2. #include "raylib.h"
  3. #include "scene.h"
  4. #include "render_state.h"
  5. #include "entities/ui_fps_entity.h"
  6. #include "entities/background_entity.h"
  7. #include "components/sprite_component.h"
  8. #include "components/panel_component.h"
  9. using namespace std::string_literals;
  10. int main() {
  11. InitWindow(800, 600, "Example");
  12. ant::core::scene::current = std::make_shared<ant::core::scene>();
  13. ant::core::scene::current->root_nodes.push_back(ant::core::make_entity<ant::entities::utilities::ui_fps_entity>());
  14. ant::core::scene::current->root_nodes.push_back(ant::core::make_entity<ant::entities::utilities::background_entity>(BLACK));
  15. ant::core::scene::current->root_nodes.push_back(ant::core::make_entity<ant::core::entity>());
  16. ant::core::scene::current->root_nodes.back()
  17. ->add_component<ant::components::graphical::sprite_component>(
  18. "Engine/assets/apple.png"s,
  19. 0,
  20. ant::core::transform<>{{560/2, 640/2}, 60},
  21. ant::core::Vec2<>{0.5,0.5}
  22. );
  23. ant::core::scene::current->root_nodes.back()->transform().position = {250,250};
  24. ant::core::scene::current->root_nodes.back()->transform().angle = 120;
  25. ant::core::scene::current->root_nodes.push_back(ant::core::make_entity<ant::core::entity>());
  26. ant::core::scene::current->root_nodes.back()
  27. ->add_component<ant::components::ui::panel_component>(
  28. 100,
  29. BLUE,
  30. ant::core::Vec2<>{400, 400},
  31. ant::core::Vec2<>{1,1}
  32. );
  33. ant::core::scene::current->root_nodes.back()->transform().position = {390, 10};
  34. auto child = ant::core::make_entity(ant::core::scene::current->root_nodes.back());
  35. child->transform().position = {150,150};
  36. child
  37. ->add_component<ant::components::ui::panel_component>(
  38. 12,
  39. RED,
  40. ant::core::Vec2<>{100, 100},
  41. ant::core::Vec2<>{1,1}
  42. )->initialize();
  43. // TODO: investigate the rendering of subpanels
  44. auto ref = std::chrono::steady_clock::now();
  45. std::chrono::duration<double> frame_time = ref - ref;
  46. while(not WindowShouldClose()) {
  47. std::cout << "Frame start\n";
  48. ant::core::scene::current->update(frame_time);
  49. ant::core::scene::current->render();
  50. BeginDrawing();
  51. ant::render::render_all();
  52. EndDrawing();
  53. auto new_time = std::chrono::steady_clock::now();
  54. frame_time = new_time - ref;
  55. ref = new_time;
  56. }
  57. CloseWindow();
  58. return 0;
  59. }