Advertisement
Guest User

Untitled

a guest
Jun 28th, 2013
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <SFML/Window.hpp>
  3.  
  4. class Game
  5. {
  6. public:
  7.     // Access for getting singleton reference
  8.     static Game& GetInstance()
  9.     {
  10.         static Game game;
  11.         return game;
  12.     };
  13.  
  14.     // Public member functions
  15.     void Start()
  16.     {
  17.         m_window.create(sf::VideoMode(800, 600), "MyNetGame");
  18.  
  19.         sf::Font font;
  20.         font.loadFromFile("sheets/DroidSansMono.ttf");
  21.         sf::Text * p_connectText = new sf::Text("test", font);
  22.         p_connectText->setColor(sf::Color::Yellow);
  23.         sf::FloatRect textRect = p_connectText->getLocalBounds();
  24.         p_connectText->setOrigin(textRect.left+textRect.width/2.0f,
  25.             textRect.top+textRect.height/2.0f);
  26.         p_connectText->setPosition(100, 100);
  27.  
  28.         m_p_text = p_connectText;
  29.     };
  30.     void Loop()
  31.     {
  32.         while (m_window.isOpen())
  33.         {
  34.             sf::Event event;
  35.             while (m_window.pollEvent(event))
  36.             {
  37.                 if (event.type == sf::Event::Closed)
  38.                     m_window.close();
  39.             }
  40.  
  41.             m_window.clear();
  42.             m_window.draw(*m_p_text);
  43.             m_window.display();
  44.         }
  45.     };
  46.  
  47. private:
  48.     // Hidden singleton/copy/assignment constructors
  49.     Game()
  50.         {};
  51.     Game(const Game&)
  52.         {};
  53.     const Game& operator=(const Game&)
  54.         {};
  55.  
  56.     // Member variables
  57.     sf::Text * m_p_text;
  58.     sf::RenderWindow m_window;
  59. };
  60.  
  61. // Program entry point
  62. int main(int argc, char** argv)
  63. {
  64.     Game::GetInstance().Start();
  65.     Game::GetInstance().Loop();
  66.     return 0;
  67. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement