Repository navigation
Expand file tree
/
Copy pathPauseState.cpp
More file actions
89 lines (74 loc) · 1.97 KB
/
Copy pathPauseState.cpp
File metadata and controls
89 lines (74 loc) · 1.97 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
#include <iostream>
#include "PauseState.h"
#include "TextureManager.h"
#include "Input.h"
#include "Game.h"
#include "GSM.h"
#include "MenuButton.h"
#include "MainMenuState.h"
#include "StateParser.h"
const std::string PauseState::s_pauseID = "PAUSE";
void PauseState::update()
{
for (int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->update();
}
}
void PauseState::render()
{
for (int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->draw();
}
}
bool PauseState::onEnter()
{
StateParser stateParser;
stateParser.parseState("test.xml", s_pauseID, &m_gameObjects, &m_textureIDList);
m_callbacks.push_back(0);
m_callbacks.push_back(s_pauseToMain);
m_callbacks.push_back(s_resumePlay);
setCallbacks(m_callbacks);
std::cout << "entering PauseState" << std::endl;
return true;
}
bool PauseState::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]);
}
// reset the mouse button states to false
IH::Instance()->reset();
std::cout << "exiting PauseState" << std::endl;
return true;
}
void PauseState::s_pauseToMain()
{
// Fixed, read MenuState.cpp
Simon::Instance()->getStateMachine()->changeState(new MainMenuState());
}
void PauseState::s_resumePlay()
{
Simon::Instance()->getStateMachine()->popState();
}
void PauseState::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()]);
}
}
}