Advertisement
Guest User

game

a guest
Jul 23rd, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Game.h"
  3. #include "MainMenu.h"
  4. #include "SplashScreen.h"
  5.  
  6. void Game::Start(void)
  7. {
  8. if(_gameState != Uninitialized)
  9. return;
  10.  
  11. _mainWindow.Create(sf::VideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,32),"Welcome to Tank!");
  12.  
  13. //_mainWindow.SetFramerateLimit(60);
  14.  
  15. Playertank *player1 = new Playertank();
  16. player1->SetPosition((SCREEN_WIDTH/2),700);
  17.  
  18. Playertanktwo *player2 = new Playertanktwo();
  19. player2->SetPosition((SCREEN_WIDTH/2),40);
  20.  
  21.  
  22.  
  23. _gameObjectManager.Add("tank1",player1);
  24.  
  25. _gameObjectManager.Add("tank2",player2);
  26.  
  27. _gameState= Game::ShowingSplash;
  28.  
  29.  
  30. while(!IsExiting())
  31. {
  32. GameLoop();
  33. }
  34.  
  35. _mainWindow.Close();
  36. }
  37.  
  38. bool Game::IsExiting()
  39. {
  40. if(_gameState == Game::Exiting)
  41. return true;
  42. else
  43. return false;
  44. }
  45.  
  46.  
  47. sf::RenderWindow& Game::GetWindow()
  48. {
  49. return _mainWindow;
  50. }
  51.  
  52. const sf::Input& Game::GetInput()
  53. {
  54. return _mainWindow.GetInput();
  55. }
  56.  
  57. void Game::GameLoop()
  58. {
  59. sf::Event currentEvent;
  60. _mainWindow.GetEvent(currentEvent);
  61.  
  62.  
  63. switch(_gameState)
  64. {
  65. case Game::ShowingMenu:
  66. {
  67. ShowMenu();
  68. break;
  69. }
  70. case Game::ShowingSplash:
  71. {
  72. ShowSplashScreen();
  73. break;
  74. }
  75. case Game::Playing:
  76. {
  77. _mainWindow.Clear(sf::Color(0,0,0));
  78.  
  79. _gameObjectManager.UpdateAll();
  80. _gameObjectManager.DrawAll(_mainWindow);
  81.  
  82. _mainWindow.Display();
  83. if(currentEvent.Type == sf::Event::Closed) _gameState = Game::Exiting;
  84.  
  85. if(currentEvent.Type == sf::Event::KeyPressed)
  86. {
  87. if(currentEvent.Key.Code == sf::Key::Escape) ShowMenu();
  88. }
  89.  
  90. break;
  91. }
  92. }
  93. }
  94.  
  95. void Game::ShowSplashScreen()
  96. {
  97. SplashScreen splashScreen;
  98. splashScreen.Show(_mainWindow);
  99. _gameState = Game::ShowingMenu;
  100. }
  101.  
  102. void Game::ShowMenu()
  103. {
  104. MainMenu mainMenu;
  105. MainMenu::MenuResult result = mainMenu.Show(_mainWindow);
  106. switch(result)
  107. {
  108. case MainMenu::Exit:
  109. _gameState = Exiting;
  110. break;
  111. case MainMenu::Play:
  112. _gameState = Playing;
  113. break;
  114. }
  115. }
  116.  
  117. Game::GameState Game::_gameState = Uninitialized;
  118. sf::RenderWindow Game::_mainWindow;
  119. GameObjectManager Game::_gameObjectManager;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement