-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameLoading.cpp
More file actions
65 lines (55 loc) · 1.3 KB
/
GameLoading.cpp
File metadata and controls
65 lines (55 loc) · 1.3 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
#include "GameLoading.h"
#include <iostream>
#include "GamePlay.h"
GameLoading::GameLoading(int width, int height, sf::RenderWindow* window, GameStateManager* gameStateManager)
{
this->window = window;
this->gameStateManager = gameStateManager;
this->width = width;
this->height = height;
}
void GameLoading::Init()
{
if (!font.loadFromFile("./Assets/Fonts/landsand.otf"))
{
std::cout << "Failed font load!" << std::endl;
}
title = sf::Text("Loading...", font, 160);
sf::Vector2u winSize = window->getSize();
sf::FloatRect titleRect = title.getLocalBounds();
title.setOrigin(sf::Vector2f(titleRect.left + titleRect.width / 2.0f, titleRect.top + titleRect.height / 2.0f));
title.setPosition(sf::Vector2f(winSize.x / 2.f, winSize.y / 2.f));
}
void GameLoading::Cleanup()
{
}
void GameLoading::Pause()
{
}
void GameLoading::Resume()
{
}
void GameLoading::GetEvents()
{
sf::Event event;
while (window->pollEvent(event))
{
if (event.type == sf::Event::Closed)
window->close();
}
}
void GameLoading::Update()
{
sf::Time elapsed = clock.getElapsedTime();
if (elapsed.asMilliseconds() >= 500)
{
gameStateManager->ChangeState(new GamePlay(width, height, window, gameStateManager));
return;
}
}
void GameLoading::Display()
{
window->clear(sf::Color::Black);
window->draw(title);
window->display();
}