-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameOverState.cpp
More file actions
97 lines (65 loc) · 2.08 KB
/
GameOverState.cpp
File metadata and controls
97 lines (65 loc) · 2.08 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
#include "GameOverState.h"
#include "Game.h"
#include "MenuState.h"
#include "PlayState.h"
#include "MenuButtons.h"
#include "AnimatedGraphic.h"
//define static variable
const std::string GameOverState::s_gameOverID = "GAMEOVER";
//define static functions
void GameOverState::s_gameOverToMain()
{
TheGame::Instance()->getStateMachine()->changeState(new MenuState());
}
void GameOverState::s_restartPlay()
{
TheGame::Instance()->getStateMachine()->changeState(new PlayState());
}
bool GameOverState::onEnter()
{
if(!TheTextureManager::Instance()->load("Resources/game-over.png", "gameovertext", TheGame::Instance()->getRenderer()))
{
return false;
}
if(!TheTextureManager::Instance()->load("Resources/main-menu.png", "mainbutton", TheGame::Instance()->getRenderer()))
{
return false;
}
if(!TheTextureManager::Instance()->load("Resources/restart-button.png", "restartbutton", TheGame::Instance()->getRenderer()))
{
return false;
}
// ( pParams, animSpeed)
GameObject* gameOverText = new AnimatedGraphic(new LoaderParams(230, 100, 190, 30, "gameovertext"), 4);
GameObject* button1 = new MenuButtons(new LoaderParams(150, 200, 350, 90, "mainbutton"), s_gameOverToMain);
GameObject* button2 = new MenuButtons(new LoaderParams(150, 300, 350, 90, "restartbutton"), s_restartPlay);
m_gameObjects.push_back(gameOverText);
m_gameObjects.push_back(button1);
m_gameObjects.push_back(button2);
std::cout << "Enter GameOverState\n";
return true;
}
bool GameOverState::onExit()
{
for(int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->clean();
}
m_gameObjects.clear();
std::cout << "Exiting GameOverState \n";
return true;
}
void GameOverState::update()
{
for(int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->update();
}
}
void GameOverState::render()
{
for(int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->draw();
}
}