-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEndlessGame.cpp
60 lines (51 loc) · 1.31 KB
/
EndlessGame.cpp
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
#include "EndlessGame.h"
//TODO: speed depends on the song speed. the song speed up after every round
EndlessGame::EndlessGame(StateManager &stateManager, std::string folderPath) : GameBase(stateManager, folderPath)
{
}
EndlessGame::~EndlessGame()
{
}
void EndlessGame::tick(const float & dt, sf::RenderWindow& window)
{
if (isGameOver) return;
GameBase::tick(dt, window);
frameCount++;
// restart song if not game over
if (!isGameOver && sound.getStatus() == sf::SoundSource::Status::Stopped)
{
sound.play();
}
}
void EndlessGame::gameOver()
{
GameBase::gameOver();
highscores->endless = std::max(highscores->endless, score);
GameSettings::getInstance()->saveHighscores();
}
void EndlessGame::keyEvent(const float & dt, sf::Event event)
{
GameBase::keyEvent(dt, event);
}
void EndlessGame::mouseEvent(const float & dt, sf::RenderWindow& window, sf::Event event)
{
GameBase::mouseEvent(dt, window, event);
if (isGameOver && !hsSaved)
{
hsSaved = true;
}
}
void EndlessGame::render(sf::RenderWindow& window)
{
using namespace std;
GameBase::render(window);
if (isGameOver)
{
GameBase::renderGameOver(window);
text.setCharacterSize(80);
text.setFillColor(sf::Color::White);
text.setString(to_string(score));
text.setPosition(1024 - text.getLocalBounds().width / 2, 576 - 250);
window.draw(text);
}
}