-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathState_Intro.cpp
65 lines (51 loc) · 1.94 KB
/
State_Intro.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
#include "State_Intro.hpp"
#include "StateManager.hpp"
State_Intro::State_Intro(StateManager* l_stateManager)
: BaseState(l_stateManager){}
State_Intro::~State_Intro(){}
void State_Intro::OnCreate(){
m_timePassed = 0.0f;
sf::Vector2u windowSize = m_stateMgr->GetContext()->m_wind->GetRenderWindow()->getSize();
m_introTexture.loadFromFile("intro.png");
m_introSprite.setTexture(m_introTexture);
m_introSprite.setOrigin(m_introTexture.getSize().x / 2.0f,
m_introTexture.getSize().y / 2.0f);
m_introSprite.setPosition(windowSize.x / 2.0f, 0);
m_font.loadFromFile("arial.ttf");
m_text.setFont(m_font);
m_text.setString({ "Press SPACE to continue" });
m_text.setCharacterSize(15);
sf::FloatRect textRect = m_text.getLocalBounds();
m_text.setOrigin(textRect.left + textRect.width / 2.0f,
textRect.top + textRect.height / 2.0f);
m_text.setPosition(windowSize.x / 2.0f, windowSize.y / 2.0f);
EventManager* evMgr = m_stateMgr->GetContext()->m_eventManager;
evMgr->AddCallback(StateType::Intro,"Intro_Continue",&State_Intro::Continue,this);
}
void State_Intro::OnDestroy(){
EventManager* evMgr = m_stateMgr->GetContext()->m_eventManager;
evMgr->RemoveCallback(StateType::Intro,"Intro_Continue");
}
void State_Intro::Update(const sf::Time& l_time){
if(m_timePassed < 5.0f){ // Less than five seconds.
m_timePassed += l_time.asSeconds();
m_introSprite.setPosition(
m_introSprite.getPosition().x,
m_introSprite.getPosition().y + (48 * l_time.asSeconds()));
}
}
void State_Intro::Draw(){
sf::RenderWindow* window = m_stateMgr->GetContext()->m_wind->GetRenderWindow();
window->draw(m_introSprite);
if(m_timePassed >= 5.0f){
window->draw(m_text);
}
}
void State_Intro::Continue(EventDetails* l_details){
if(m_timePassed >= 5.0f){
m_stateMgr->SwitchTo(StateType::MainMenu);
m_stateMgr->Remove(StateType::Intro);
}
}
void State_Intro::Activate(){}
void State_Intro::Deactivate(){}