-
-
Save anonymous/98a51a080621ca3d092a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include "Game.h" | |
#include "MainMenu.h" | |
#include "SplashScreen.h" | |
void Game::Start(void) | |
{ | |
if(_gameState != Uninitialized) | |
return; | |
_mainWindow.Create(sf::VideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,32),"Welcome to Tank!"); | |
//_mainWindow.SetFramerateLimit(60); | |
Playertank *player1 = new Playertank(); | |
player1->SetPosition((SCREEN_WIDTH/2),700); | |
Playertanktwo *player2 = new Playertanktwo(); | |
player2->SetPosition((SCREEN_WIDTH/2),40); | |
_gameObjectManager.Add("tank1",player1); | |
_gameObjectManager.Add("tank2",player2); | |
_gameState= Game::ShowingSplash; | |
while(!IsExiting()) | |
{ | |
GameLoop(); | |
} | |
_mainWindow.Close(); | |
} | |
bool Game::IsExiting() | |
{ | |
if(_gameState == Game::Exiting) | |
return true; | |
else | |
return false; | |
} | |
sf::RenderWindow& Game::GetWindow() | |
{ | |
return _mainWindow; | |
} | |
const sf::Input& Game::GetInput() | |
{ | |
return _mainWindow.GetInput(); | |
} | |
void Game::GameLoop() | |
{ | |
sf::Event currentEvent; | |
_mainWindow.GetEvent(currentEvent); | |
switch(_gameState) | |
{ | |
case Game::ShowingMenu: | |
{ | |
ShowMenu(); | |
break; | |
} | |
case Game::ShowingSplash: | |
{ | |
ShowSplashScreen(); | |
break; | |
} | |
case Game::Playing: | |
{ | |
_mainWindow.Clear(sf::Color(0,0,0)); | |
_gameObjectManager.UpdateAll(); | |
_gameObjectManager.DrawAll(_mainWindow); | |
_mainWindow.Display(); | |
if(currentEvent.Type == sf::Event::Closed) _gameState = Game::Exiting; | |
if(currentEvent.Type == sf::Event::KeyPressed) | |
{ | |
if(currentEvent.Key.Code == sf::Key::Escape) ShowMenu(); | |
} | |
break; | |
} | |
} | |
} | |
void Game::ShowSplashScreen() | |
{ | |
SplashScreen splashScreen; | |
splashScreen.Show(_mainWindow); | |
_gameState = Game::ShowingMenu; | |
} | |
void Game::ShowMenu() | |
{ | |
MainMenu mainMenu; | |
MainMenu::MenuResult result = mainMenu.Show(_mainWindow); | |
switch(result) | |
{ | |
case MainMenu::Exit: | |
_gameState = Exiting; | |
break; | |
case MainMenu::Play: | |
_gameState = Playing; | |
break; | |
} | |
} | |
Game::GameState Game::_gameState = Uninitialized; | |
sf::RenderWindow Game::_mainWindow; | |
GameObjectManager Game::_gameObjectManager; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment