-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameWinScene.cpp
More file actions
75 lines (65 loc) · 2.73 KB
/
GameWinScene.cpp
File metadata and controls
75 lines (65 loc) · 2.73 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
// =================
// GAMEWINSCENE.CPP
// implements the game win scene
// =================
#include "header/GameWinScene.h"
#include "header/MainMenuScene.h"
#include "header/GameplayScene.h"
#include <SFML/Graphics.hpp>
#include <iostream>
#include <optional>
GameWinScene::GameWinScene(SceneManager& manager, AudioManager& audio, int score)
: sceneManager(manager), audio(audio), score(score) {
}
// initializes the text objects for the win screen, including styling and positioning
void GameWinScene::init() {
if (!font.openFromFile("assets/ka1.ttf")) {
std::cerr << "Failed to load font\n";
}
titleText.emplace(font, "GAME COMPLETE!", 48);
titleText->setFillColor(sf::Color::Green);
titleText->setOutlineColor(sf::Color::Black);
titleText->setOutlineThickness(4.f);
titleText->setOrigin({ titleText->getLocalBounds().size.x / 2.f, titleText->getLocalBounds().size.y / 2.f });
titleText->setPosition({ 400.f, 200.f });
scoreText.emplace(font, "FINAL SCORE " + std::to_string(score), 28);
scoreText->setFillColor(sf::Color::Yellow);
scoreText->setOutlineColor(sf::Color::Black);
scoreText->setOutlineThickness(3.f);
scoreText->setOrigin({ scoreText->getLocalBounds().size.x / 2.f, scoreText->getLocalBounds().size.y / 2.f });
scoreText->setPosition({ 400.f, 275.f });
menuText.emplace(font, "PRESS M FOR MAIN MENU", 20);
menuText->setFillColor(sf::Color::Blue);
menuText->setOrigin({ menuText->getLocalBounds().size.x / 2.f, menuText->getLocalBounds().size.y / 2.f });
menuText->setPosition({ 400.f, 400.f });
quitText.emplace(font, "PRESS Q TO QUIT GAME", 20);
quitText->setFillColor(sf::Color::Red);
quitText->setOrigin({ quitText->getLocalBounds().size.x / 2.f, quitText->getLocalBounds().size.y / 2.f });
quitText->setPosition({ 400.f, 450.f });
}
void GameWinScene::handleInput(sf::RenderWindow& window) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::M)) {
audio.stopWin();
audio.playMenuMusic();
sceneManager.pushScene(std::make_unique<MainMenuScene>(sceneManager), true);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Q)) {
window.close();
}
}
void GameWinScene::update(float deltaTime) {
// toggles the title text visibility for the flicker effect
flickerTimer += deltaTime;
if (flickerTimer >= FLICKER_RATE) {
flickerTimer = 0.f;
isFlickering = !isFlickering;
}
}
// renders the win screen
void GameWinScene::render(sf::RenderWindow& window) {
window.clear(sf::Color(20, 20, 20));
if (titleText && isFlickering) window.draw(*titleText);
if (scoreText) window.draw(*scoreText);
if (menuText) window.draw(*menuText);
if (quitText) window.draw(*quitText);
}