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