-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameOver.cpp
More file actions
58 lines (49 loc) · 1.82 KB
/
Copy pathGameOver.cpp
File metadata and controls
58 lines (49 loc) · 1.82 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
#include "GameOver.h"
#include "GameEngine.h"
#include "GameEngineConfig.h"
#include "UiComponent.h"
#include "Background.h"
#include "Button.h"
#include "SpriteComponent.h"
#include "TextContainer.h"
#include "HUD.h"
#include <string>
#include <iostream>
GameOver::GameOver() {
music = "over";
sf::RenderWindow& window = GameEngine::getInstance().getWindow();
float centerX = window.getSize().x / 2.f;
float centerY = window.getSize().y / 2.f;
Background* background = new Background("Green_Nebula_05.png");
components.push_back(background);
scoreText = new TextContainer("PressStart2P", "Score: " + std::to_string(HUD::getInstance()->getScore()));
scoreText->setPosition(centerX - scoreText->getSize().x / 2.f, centerY - scoreText->getSize().y / 2.f);
components.push_back(scoreText);
Button* closeButton = new Button("Close");
closeButton->setPosition({ centerX - closeButton->getSize().x / 2.f , window.getSize().y - 350.f});
closeButton->setCallback([]() {
sf::RenderWindow& window = GameEngine::getInstance().getWindow();
window.close();
});
components.push_back(closeButton);
}
GameOver::~GameOver() {
for (UiComponent* component : components) {
delete component;
}
components.clear();
}
void GameOver::draw() {
for (UiComponent* component : components) {
component->draw();
}
}
void GameOver::update() {
GameEngine::getInstance().showCursor(true);
sf::RenderWindow& window = GameEngine::getInstance().getWindow();
scoreText->setText("Score: " + std::to_string(HUD::getInstance()->getScore()));
scoreText->setPosition(window.getSize().x / 2.f - scoreText->getSize().x / 2.f, window.getSize().y / 2.f - scoreText->getSize().y / 2.f);
for (UiComponent* component : components) {
component->update();
}
}