-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPauseState.cpp
More file actions
79 lines (57 loc) · 1.68 KB
/
PauseState.cpp
File metadata and controls
79 lines (57 loc) · 1.68 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
#include "PauseState.h"
#include "Game.h"
#include "MenuButtons.h"
const std::string PauseState::s_pauseID = "PAUSE";
void PauseState::s_pauseToMain()
{
TheGame::Instance()->getStateMachine()->changeState(new MenuState());
}
void PauseState::s_resumePlay()
{
TheGame::Instance()->getStateMachine()->popState();
}
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()
{
if(!TheTextureManager::Instance()->load("Resources/resume.png", "resumebutton", TheGame::Instance()->getRenderer()))
{
return false;
}
if(!TheTextureManager::Instance()->load("Resources/main-menu.png", "mainbutton", TheGame::Instance()->getRenderer()))
{
return false;
}
GameObject* button1 = new MenuButtons(new LoaderParams(150, 100, 350, 90, "mainbutton"), s_pauseToMain);
GameObject* button2 = new MenuButtons(new LoaderParams(150, 300, 350, 90, "resumebutton"), s_resumePlay);
m_gameObjects.push_back(button1);
m_gameObjects.push_back(button2);
std::cout << "Pause State ON\n";
return true;
}
bool PauseState::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");
// reset mouse button states to false
TheInputHandler::Instance()->reset();
std::cout << "Pause State OFF\n";
return true;
}