-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuState.cpp
More file actions
103 lines (59 loc) · 1.74 KB
/
MenuState.cpp
File metadata and controls
103 lines (59 loc) · 1.74 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
92
93
94
95
96
97
98
99
100
101
102
103
#include "MenuState.h"
#include "Game.h"
#include "MenuButtons.h"
#include "PlayState.h"
//need to clean up those includes
const std::string MenuState::s_menuID = "MENU";
bool MenuState::onEnter()
{
if(!TheTextureManager::Instance()->load("Resources/play-button.png", "playbutton", TheGame::Instance()->getRenderer()))
{
return false;
}
if(!TheTextureManager::Instance()->load("Resources/exit-button.png", "exitbutton", TheGame::Instance()->getRenderer()))
{
return false;
}
GameObject* button1 = new MenuButtons(new LoaderParams(150, 100, 350, 90, "playbutton"), s_menuToPlay);
GameObject* button2 = new MenuButtons(new LoaderParams(150, 300, 350, 90, "exitbutton"), s_exitFromMenu);
m_gameObjects.push_back(button1);
m_gameObjects.push_back(button2);
std::cout << "Entering MenuState\n";
return true;
}
bool MenuState::onExit()
{
for(int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->clean();
}
m_gameObjects.clear();
TheTextureManager::Instance()->clearFromTextureMap("playbutton");
TheTextureManager::Instance()->clearFromTextureMap("exitbutton");
std::cout << "Exiting MenuState \n";
return true;
}
void MenuState::update()
{
for(int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->update();
}
}
void MenuState::render()
{
for(int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->draw();
}
}
void MenuState::s_menuToPlay()
{
std::cout << "Play button clicked\n";
TheGame::Instance()->getStateMachine()->changeState(new PlayState());
}
void MenuState::s_exitFromMenu()
{
std::cout << "Exit button clicked\n";
TheGame::Instance()->quit();
}