Repository navigation
Expand file tree
/
Copy pathGameOverState.cpp
More file actions
91 lines (79 loc) · 2.21 KB
/
Copy pathGameOverState.cpp
File metadata and controls
91 lines (79 loc) · 2.21 KB
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
85
86
87
88
89
90
91
#include <iostream>
#include "GameOverState.h"
#include "Game.h"
#include "MainMenuState.h"
#include "PlayState.h"
#include "GameOverState.h"
#include "Input.h"
#include "PauseState.h"
#include "LoaderParams.h"
#include "MenuButton.h"
#include "StateParser.h"
const std::string GameOverState::s_gameOverID = "GAMEOVER";
void GameOverState::update()
{
if (IH::Instance()->isKeyDown(SDL_SCANCODE_ESCAPE)) //pause when user hits escape
{
Simon::Instance()->getStateMachine()->pushState(new PauseState());
}
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()
{
// parse the state
StateParser stateParser;
stateParser.parseState("test.xml", s_gameOverID, &m_gameObjects, &m_textureIDList);
m_callbacks.push_back(0);
m_callbacks.push_back(s_gameOverToMain);
m_callbacks.push_back(s_restartPlay);
// set the callbacks for menu items
setCallbacks(m_callbacks);
std::cout << "entering GameOverState" << std::endl;
return true;
}
bool GameOverState::onExit()
{
for (int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->clean();
}
m_gameObjects.clear();
// clear the texture manager
for (int i = 0; i < m_textureIDList.size(); i++)
{
TheTextureManager::Instance()->clearFromTextureMap(m_textureIDList[i]);
}
std::cout << "exiting GameOverState" << std::endl;;
return true;
}
void GameOverState::s_gameOverToMain()
{
Simon::Instance()->getStateMachine()->changeState(new MainMenuState());
}
void GameOverState::s_restartPlay()
{
Simon::Instance()->getStateMachine()->changeState(new PlayState());
}
void GameOverState::setCallbacks(const std::vector<Callback>& callbacks)
{
// go through the game objects
for (int i = 0; i < m_gameObjects.size(); i++)
{
// if they are of type MenuButton then assign a callback based on the id passed in from the file
if (dynamic_cast<MenuButton*>(m_gameObjects[i]))
{
MenuButton* pButton = dynamic_cast<MenuButton*>(m_gameObjects[i]);
pButton->setCallback(callbacks[pButton->getCallbackID()]);
}
}
}