Advertisement
Vinnysses

Untitled

Apr 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class Show : public ApplicationListener {
  2. std::vector<std::unique_ptr<ApplicationListener>> apps{};
  3. size_t current_app = 0;
  4. size_t prev_app = 0;
  5.  
  6.  
  7. public:
  8. Show() {
  9. apps.push_back(std::make_unique<StartScreen>());
  10. apps.push_back(std::make_unique<Gradius>());
  11. apps.push_back(std::make_unique<GameOver>());
  12.  
  13. prev_app = apps.size();
  14. current_app = 0;
  15. }
  16.  
  17. void OnRender(Context &ctx) override {
  18. if (prev_app != current_app) {
  19. if (prev_app != apps.size()) {
  20. apps.at(prev_app)->OnDispose(ctx);
  21. }
  22. apps.at(current_app)->OnCreate(ctx);
  23. prev_app = current_app;
  24. }
  25.  
  26. apps.at(current_app)->OnRender(ctx);
  27.  
  28. if (IsClicked(ctx, Button::KEY_G)) {
  29. current_app = (current_app + 1) % apps.size();
  30. LogInfo("Transition to the %d", current_app);
  31. }
  32. if (IsClicked(ctx, Button::KEY_ESCAPE)) {
  33. ExitApp(ctx);
  34. }
  35. }
  36.  
  37. ~Show() override {
  38. apps.clear();
  39. }
  40. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement