app.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * 2D Physic Engine
  3. * app.cpp: basic application handling.
  4. * Based on pikuma.com Learn Game Physics Engine Programming course.
  5. * Copyright (c) 2022 986-Studio. All rights reserved.
  6. *
  7. * Created by Manoël Trapier on 07/06/2022.
  8. */
  9. #include <app.h>
  10. #include <graphics.h>
  11. #include <imgui.h>
  12. #include <imgui_sdl.h>
  13. #include <imgui_impl_sdl.h>
  14. void application::parseParameters(int argc, char *argv[])
  15. {
  16. // Nothing to do for now
  17. }
  18. void application::setup()
  19. {
  20. this->running = graphics::openWindow();
  21. this->part = new particle(50, 100, 1.0);
  22. }
  23. void application::input()
  24. {
  25. SDL_Event event;
  26. while(SDL_PollEvent(&event))
  27. {
  28. //ImGui_ImplSDL2_ProcessEvent(&event);
  29. //ImGuiIO &io = ImGui::GetIO();
  30. switch(event.type)
  31. {
  32. case SDL_QUIT:
  33. this->running = false;
  34. break;
  35. case SDL_KEYDOWN:
  36. if (event.key.keysym.sym == SDLK_ESCAPE)
  37. {
  38. this->running = false;
  39. }
  40. break;
  41. }
  42. }
  43. }
  44. void application::update()
  45. {
  46. // Nothing for now.
  47. }
  48. void application::render()
  49. {
  50. graphics::clearScreen(0xFF056263);
  51. graphics::draw::fillCircle(this->part->position.x, this->part->position.y, 4, 0xFFFFFFFF);
  52. graphics::renderFrame();
  53. }
  54. void application::destroy()
  55. {
  56. // Nothing for now.
  57. graphics::closeWindow();
  58. delete this->part;
  59. }