Advertisement
Guest User

Engine.cpp

a guest
Oct 16th, 2013
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Engine.h"
  3.  
  4. void Engine::Start(void)
  5. {
  6.     if (gameState != Uninitialized)
  7.         return;
  8.  
  9.     gameWindow.create(sf::VideoMode(1024, 768, 32), "Hope Rides Alone!");
  10.     gameState = Engine::Playing;
  11.  
  12.     while (!IsExiting())
  13.     {
  14.         GameLoop();
  15.     }
  16.  
  17.     gameWindow.close();
  18. }
  19.  
  20. bool Engine::IsExiting()
  21. {
  22.     if (gameState == Engine::Exiting)
  23.         return true;
  24.     else
  25.         return false;
  26. }
  27.  
  28. void Engine::GameLoop()
  29. {
  30.     sf::Event currentEvent;
  31.     while(gameWindow.pollEvent(currentEvent))
  32.     {
  33.  
  34.         switch(gameState)
  35.         {
  36.             case Engine::Playing:
  37.             {
  38.                 gameWindow.clear(sf::Color(255,0,0));
  39.                 gameWindow.display();
  40.                
  41.                 if(currentEvent.type == sf::Event::Closed)
  42.                 {
  43.                     gameState = Engine::Exiting;
  44.                 }
  45.                 break;
  46.             }
  47.         }
  48.     }
  49. }
  50.  
  51. Engine::GameState Engine::gameState = Uninitialized;
  52. sf::RenderWindow gameWindow;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement