|
| 1 | +#include "GameOverState.h" |
| 2 | +#include "Game.h" |
| 3 | +#include "TextureManager.h" |
| 4 | + |
| 5 | +const string GameOverState::s_gameOverID = "GAMEOVER"; |
| 6 | + |
| 7 | +GameOverState::GameOverState() |
| 8 | +{ |
| 9 | + |
| 10 | +} |
| 11 | + |
| 12 | +void GameOverState::s_gameOverToMain() |
| 13 | +{ |
| 14 | + TheGame::Instance()->getStateMachine()->changeState(new MenuState()); |
| 15 | +} |
| 16 | + |
| 17 | +void GameOverState::s_restartPlay() |
| 18 | +{ |
| 19 | + TheGame::Instance()->getStateMachine()->changeState(new PlayState()); |
| 20 | +} |
| 21 | + |
| 22 | +void GameOverState::update() |
| 23 | +{ |
| 24 | + for (int i = 0; i < m_gameObjects.size(); i++) |
| 25 | + { |
| 26 | + m_gameObjects[i]->update(); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +void GameOverState::render() |
| 31 | +{ |
| 32 | + for (int i = 0; i < m_gameObjects.size(); i++) |
| 33 | + { |
| 34 | + m_gameObjects[i]->draw(); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +bool GameOverState::onEnter() |
| 39 | +{ |
| 40 | + if(!TheTextureManager::Instance()->load("img/gameover.png", "gameovertext", TheGame::Instance()->getRenderer())) |
| 41 | + { |
| 42 | + return false; //can't load texutre, error |
| 43 | + } |
| 44 | + if (!TheTextureManager::Instance()->load("img/main.png", "mainbutton", TheGame::Instance()->getRenderer())) |
| 45 | + { |
| 46 | + return false; //can't load texture, error |
| 47 | + } |
| 48 | + if(!TheTextureManager::Instance()->load("img/restart.png", "restartbutton", TheGame::Instance()->getRenderer())) |
| 49 | + { |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + GameObject* gameOverText = new AnimatedGraphic(new LoaderParams(200, 100, 190, 30, 2, "gameovertext"), 2); |
| 54 | + GameObject* button1 = new MenuButton(new LoaderParams(200, 200, 200, 80, 3, "mainbutton"), s_gameOverToMain); |
| 55 | + GameObject* button2 = new MenuButton(new LoaderParams(200, 300, 200, 80, 3, "restartbutton"), s_restartPlay); |
| 56 | + |
| 57 | + m_gameObjects.push_back(gameOverText); |
| 58 | + m_gameObjects.push_back(button1); |
| 59 | + m_gameObjects.push_back(button2); |
| 60 | + |
| 61 | + cout << "entering GameOverState" << endl; |
| 62 | + return true; |
| 63 | +} |
| 64 | + |
| 65 | +bool GameOverState::onExit() |
| 66 | +{ |
| 67 | + for (int i = 0; i < m_gameObjects.size(); i++) |
| 68 | + { |
| 69 | + m_gameObjects[i]->clean(); |
| 70 | + } |
| 71 | + m_gameObjects.clear(); |
| 72 | + |
| 73 | + TheTextureManager::Instance()->clearFromTextureMap("resumebutton"); |
| 74 | + TheTextureManager::Instance()->clearFromTextureMap("mainbutton"); |
| 75 | + |
| 76 | + cout << "exiting GameOverState" << endl; |
| 77 | + return true; |
| 78 | +} |
| 79 | + |
| 80 | +string GameOverState::getStateID() const |
| 81 | +{ |
| 82 | + return s_gameOverID; |
| 83 | +} |
| 84 | + |
0 commit comments