-
Notifications
You must be signed in to change notification settings - Fork 0
/
SplashState.cpp
95 lines (75 loc) · 2.05 KB
/
SplashState.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
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
#include "stdafx.h"
#pragma once
#include <sstream>
#include "SplashState.h"
#include "DEFINITIONS.h"
#include "MainMenuState.h"
#include <iostream>
namespace EnglishEducator
{
SplashState::SplashState(GameDataRef data) : _data(data)
{
}
void SplashState::Init()
{
_data->assets.LoadTexture("Splash State Background",
SPLASH_SCENE_BACKGROUND_FILEPATH);
_data->assets.LoadFont("KG Happy", KGHAPPY_FONT_FILEPATH);
_data->assets.LoadFont("Wunderland", WUNDERLAND_FONT_FILEPATH);
_background.setTexture(this->_data->assets.GetTexture("Splash State Background"));
_text.setFont(_data->assets.GetFont("KG Happy"));
_text.setString("This game was made\nfor everyone :)");
_text.setCharacterSize(72);
_text.setFillColor(sf::Color(255, 255, 255, 0));
_text.setOrigin(_text.getGlobalBounds().width / 2,
_text.getGlobalBounds().height / 2);
_text.setPosition(_data->window.getSize().x / 2,
_data->window.getSize().y / 2);
}
void SplashState::HandleInput()
{
sf::Event event;
while (_data->window.pollEvent(event))
{
if (sf::Event::Closed == event.type)
{
_data->window.close();
}
}
}
void SplashState::Update(float dt)
{
if (_clock.getElapsedTime().asSeconds() > SPLASH_STATE_SHOW_TIME)
{
_data->machine.AddState(StateRef(new MainMenuState(_data)),
true);
}
if (!disappear)
{
if (textAppearanceTime < 255)
{
textAppearanceTime += TEXT_APPEARANCE_TIME * dt;
_text.setFillColor(sf::Color(255, 255, 255, textAppearanceTime));
}
else if (textAppearanceTime == 255 && _clock.getElapsedTime().asSeconds() > 5)
{
disappear = true;
}
}
else
{
if (textAppearanceTime > 0)
{
textAppearanceTime -= TEXT_APPEARANCE_TIME * dt;
_text.setFillColor(sf::Color(255, 255, 255, textAppearanceTime));
}
}
}
void SplashState::Draw(float dt)
{
_data->window.clear();
_data->window.draw(_background);
_data->window.draw(_text);
_data->window.display();
}
}