-
Notifications
You must be signed in to change notification settings - Fork 9
/
PauseState.cpp
75 lines (60 loc) · 1.66 KB
/
PauseState.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
#include "PauseState.h"
#include "Game.h"
#include "TextureManager.h"
#include "MenuButton.h"
#include "InputHandler.h"
#include "MenuState.h"
const std::string PauseState::s_pauseID = "PAUSE";
void PauseState::update()
{
for (int i = 0; i < (int)m_gameObjects.size(); ++i)
{
m_gameObjects[i]->update();
}
}
void PauseState::render()
{
for (int i = 0; i < (int)m_gameObjects.size(); ++i)
{
m_gameObjects[i]->draw();
}
}
bool PauseState::onEnter()
{
if (!TheTextureManager::Instance()->load("assets/resume.png", "resumebutton", TheGame::Instance()->getRenderer()))
{
return false;
}
if (!TheTextureManager::Instance()->load("assets/main.png", "mainbutton", TheGame::Instance()->getRenderer()))
{
return false;
}
GameObject* button1 = new MenuButton(new LoaderParams(200, 100, 200, 80, 3, "mainbutton"), s_pauseToMain);
GameObject* button2 = new MenuButton(new LoaderParams(200, 300, 200, 80, 3, "resumebutton"), s_resumePlay);
m_gameObjects.push_back(button1);
m_gameObjects.push_back(button2);
std::cout << "entering PauseState\n";
return true;
}
bool PauseState::onExit()
{
for (int i = 0; i < (int)m_gameObjects.size(); ++i)
{
m_gameObjects[i]->clean();
}
m_gameObjects.clear();
TheTextureManager::Instance()->clearFromTextureMap("resumebutton");
TheTextureManager::Instance()->clearFromTextureMap("mainbutton");
//reset the mouse button states to false
TheInputHandler::Instance()->reset();
std::cout << "exiting PauseState\n";
return true;
}
void PauseState::s_resumePlay()
{
TheGame::Instance()->getStateMachine()->popState();
}
void PauseState::s_pauseToMain()
{
TheGame::Instance()->getStateMachine()->changeState(new MenuState());
}