-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuState.cpp
More file actions
64 lines (59 loc) · 1.5 KB
/
Copy pathMenuState.cpp
File metadata and controls
64 lines (59 loc) · 1.5 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
#include "MenuState.h"
#include <iostream>
#include "TextureManager.h"
#include "Game.h"
#include "MenuButton.h"
#include "GameObject.h"
#include "PlayState.h"
const std::string MenuState::s_menuID = "MENU";
void MenuState::MenuToPlay()
{
Game::Instance()->GetStateMachine()->PushState(new PlayState());
}
void MenuState::ExitFromMenu()
{
Game::Instance()->quit();
}
void MenuState::Update()
{
for (size_t i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->Update();
}
}
void MenuState::Render()
{
for (size_t i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->Draw();
}
}
bool MenuState::OnEnter()
{
if (!TextureManager::Instance()->load("./res/button.png","playbutton", Game::Instance()->GetRenderer()))
{
return false;
}
if (!TextureManager::Instance()->load("./res/exit.png","exitbutton", Game::Instance()->GetRenderer()))
{
return false;
}
// GameObject* button1 = new MenuButton(new LoaderParams(100, 100,200, 70, "playbutton"),MenuToPlay);
// GameObject* button2 = new MenuButton(new LoaderParams(100, 175,200, 70, "exitbutton"),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();
TextureManager::Instance()->ClearFromTextureMap("playbutton");
TextureManager::Instance()->ClearFromTextureMap("exitbutton");
std::cout << "exiting MenuState\n";
return true;
}