Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "ScreenManager.h"
  2.  
  3. ScreenManager::ScreenManager(void)
  4.     : SplashScreen(NULL), TitleScreen(NULL), currentScreen(NULL)
  5. {
  6. }
  7.  
  8.  
  9. ScreenManager::~ScreenManager()
  10. {
  11. }
  12.  
  13. ScreenManager &ScreenManager::GetInstance()
  14. {
  15.     static ScreenManager instance;
  16.     return instance;
  17. }
  18.  
  19. void ScreenManager::Initialize(SDL_Renderer *renderer)
  20. {
  21.     SplashScreen = new GameScreen;
  22.     TitleScreen = new GameScreen;
  23.  
  24.     if (SplashScreen) SplashScreen->LoadContent(renderer);
  25.     if (TitleScreen) TitleScreen->LoadContent(renderer);
  26.  
  27.     currentScreen = SplashScreen;
  28.  
  29.     /*transition = false;
  30.     fade.LoadContent(renderer);
  31.     file.LoadContent("tests.cme", attributes, contents);*/
  32. }
  33.  
  34. void ScreenManager::LoadContent(SDL_Renderer *renderer)
  35. {
  36.     currentScreen->LoadContent(renderer); // not working without this too
  37. }
  38.  
  39. void ScreenManager::Update(SDL_Renderer *renderer, SDL_Event &event)
  40. {
  41.     if(currentScreen)
  42.     {
  43.         currentScreen->Update(renderer, event);
  44.     }
  45. }
  46.  
  47. void ScreenManager::Draw(SDL_Renderer *renderer)
  48. {
  49.     if(currentScreen)
  50.     {
  51.         currentScreen->Draw(renderer);
  52.     }
  53. }
  54.  
  55. void ScreenManager::SetScreen(GameScreen *newScreen)
  56. {
  57.     currentScreen = newScreen;
  58. }
  59.  
  60. void ScreenManager::Transition(SDL_Renderer *renderer)
  61. {
  62. }
  63.  
  64. Uint8 ScreenManager::GetAlpha()
  65. {
  66.     return fade.getAlpha();
  67. }
  68.  
  69. void ScreenManager::UnloadContent()
  70. {
  71.     if (TitleScreen) TitleScreen->UnloadContent(); delete TitleScreen; TitleScreen = NULL;
  72.     if (SplashScreen) SplashScreen->UnloadContent(); delete SplashScreen; SplashScreen = NULL;
  73. }
  74.  
  75.  
  76. //-------------------------------------------------------------------------------------------------
  77.  
  78. #include "SplashScreen.h"
  79.  
  80. SplashScreen::SplashScreen()
  81. {
  82. }
  83.  
  84.  
  85. SplashScreen::~SplashScreen()
  86. {
  87. }
  88.  
  89. void SplashScreen::LoadContent(SDL_Renderer *renderer)
  90. {
  91.     this->SplashImage = ScreenManager::GetInstance().GetSplashText();
  92.     SplashImage.loadFromFile("lol.bmp", renderer);
  93.    
  94.     keys.push_back(SDLK_ESCAPE);
  95.  
  96.     /*file.LoadContent("Load/splash.cme", attributes, contents);
  97.     for (int i = 0; i < attributes.size(); i++)
  98.     {
  99.         for (int j = 0; j < attributes[i].size(); j++)
  100.         {
  101.             std::string att = attributes[i][j];
  102.             if (att == "Image")
  103.             {
  104.                 SplashImage.loadFromFile(contents[i][j], renderer);
  105.             }
  106.         }
  107.     }*/
  108. }
  109.  
  110. void SplashScreen::UnloadContent()
  111. {
  112.     GameScreen::UnloadContent();
  113. }
  114.  
  115. void SplashScreen::Draw(SDL_Renderer *renderer)
  116. {
  117.     SplashImage.render(0, 0, renderer);
  118. }
  119.  
  120. void SplashScreen::Update(SDL_Renderer *renderer, SDL_Event &event)
  121. {
  122.     input.Update(event);
  123.     if (input.KeyPressed(keys))
  124.     {
  125.         ScreenManager::GetInstance().SetScreen(ScreenManager::GetInstance().GetTitleScreen());
  126.         //ScreenManager::GetInstance().SetScreen(ScreenManager::GetInstance().GetSplashScreen()); <--- not working too
  127.         std::cout << "KEY" << std::endl;
  128.     }
  129. }
Advertisement
RAW Paste Data Copied
Advertisement