Advertisement
MrPoxipol

SFML Game game.cpp

Dec 14th, 2013
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include "Game.h"
  2.  
  3. Game::Game(sf::RenderWindow &Window)
  4.     :win(Window)
  5. {
  6.     if(!res.loadTexturesFromArchive("data/gfx", "gfx.7z", "png", TEX_NUM)) // Loading textures from game resource.
  7.     {
  8.         std::cout << "/*/** Failed to load textures from archive, HALT! **/*/" << std::endl;
  9.         exit(EXIT_FAILURE);
  10.     }
  11.  
  12.     if(!gmap.open("data/maps/test.txt")) // Test map.
  13.     {
  14.         std::cout << "/*/** Failed to open game map, HALT! **/*/" << std::endl;
  15.         exit(EXIT_FAILURE);
  16.     }
  17.  
  18.     gmap.get(20);
  19. }
  20.  
  21. void Game::renderBackgroundMap()
  22. {
  23.     /*TODO*/
  24. }
  25.  
  26. void Game::logic()
  27. {
  28.     sf::Event event;
  29.     while(win.pollEvent(event))
  30.     {
  31.         switch(event.type)
  32.         {
  33.         case sf::Event::Closed:
  34.             win.close();
  35.             break;
  36.  
  37.         default: break;
  38.         }
  39.     }
  40.  
  41.     fps.update(); // FPS time update.
  42.  
  43.     std::ostringstream o;
  44.     o << APP_NAME << " |FPS: " << (unsigned int) fps.getFPS();
  45.     win.setTitle(o.str()); // Setting title with FPS num.
  46. }
  47.  
  48. void Game::render()
  49. {
  50.     win.clear(); // Clear Background with default color - black (0,0,0)
  51.     // Drawing.
  52.     //this->renderBackgroundMap();
  53.  
  54.     win.display();
  55. }
  56.  
  57. bool Game::run()
  58. {
  59.     while(win.isOpen())
  60.     {
  61.         this->logic();
  62.         this->render();
  63.     }
  64.  
  65.     return true;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement