-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAboutScene.h
172 lines (129 loc) · 4.02 KB
/
AboutScene.h
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#pragma once
#include "../TextureLoader.h"
#include "../Particle.h"
#include "../Button.h"
#include "../ResourcePaths.h"
#include "../SaveFile.h"
#include <Segues/PushIn.h>
#include <Segues/BlendFadeIn.h>
#include <Segues/Cube3D.h>
#include <Swoosh/ActivityController.h>
#include <Swoosh/Game.h>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#define TEXT_BLOCK_INFO "Swoosh is an Activity and Segue mini library\n" \
"designed to make complex screen transitions\n" \
"a thing of the past.\n" \
"This is a proof-of-concept demo showcasing\n" \
"its features and includes helpful utilities\n" \
"for your SFML apps or games.\n\n" \
"Fork at\ngithub.com/TheMaverickProgrammer/Swoosh"
#define CONTROLS_INFO ">> Left click to shoot\n\n"\
">> Right click to boost and dodge\n\n" \
">> Collect stars for extra life\n\n"
using namespace swoosh;
using namespace swoosh::types;
class AboutScene : public Activity {
private:
sf::Texture * btn;
sf::Texture * sfmlTexture;
sf::Sprite sfml;
button goback;
sf::Font manual;
sf::Font font;
sf::Text text;
std::string info;
sf::SoundBuffer buffer;
sf::Sound selectFX;
float screenDiv;
float screenMid;
float screenBottom;
Timer timer;
bool inFocus;
bool canClick;
public:
AboutScene(ActivityController& controller) : Activity(&controller) {
canClick = false;
font.loadFromFile(GAME_FONT);
text.setFont(font);
text.setFillColor(sf::Color::White);
manual.loadFromFile(MANUAL_FONT);
btn = loadTexture(BLUE_BTN_PATH);
goback.sprite = sf::Sprite(*btn);
goback.text = "Continue";
info = TEXT_BLOCK_INFO;
sfmlTexture = loadTexture(SFML_PATH);
sfml = sf::Sprite(*sfmlTexture);
sfml.setScale(0.7f, 0.7f);
setOrigin(sfml, 0.60f, 0.60f);
sf::Vector2u windowSize = getController().getVirtualWindowSize();
setView(windowSize);
screenBottom = (float)windowSize.y;
screenMid = windowSize.x / 2.0f;
screenDiv = windowSize.y / 4.0f;
// Load sounds
buffer.loadFromFile(SHIELD_UP_SFX_PATH);
selectFX.setBuffer(buffer);
inFocus = false;
timer.start();
}
void onStart() override {
inFocus = true;
}
void onUpdate(double elapsed) override {
timer.update(sf::seconds(elapsed));
double offset = 0;
if (timer.getElapsed().asSeconds() > 3) {
offset = ease::wideParabola(timer.getElapsed().asSeconds()-3.0, 5.0, 0.9);
}
sf::Vector2u windowSize = getController().getVirtualWindowSize();
sfml.setPosition(100.0f + (float)(offset * (windowSize.x - 300)), 100.0f);
sfml.setRotation((float)(offset * 360 * 2));
goback.update(getController().getWindow());
if (goback.isClicked && inFocus) {
if (canClick) {
canClick = false;
selectFX.play();
if (goback.text == "FIN") {
using effect = segue<Cube3D<direction::right>, sec<2>>;
getController().pop<effect>();
}
else {
goback.text = "FIN";
info = CONTROLS_INFO;
}
}
}
if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && !canClick) {
canClick = true;
}
}
void onLeave() override {
inFocus = false;
}
void onExit() override {
}
void onEnter() override {
}
void onResume() override {
}
void onDraw(sf::RenderTexture& surface) override {
sf::RenderWindow& window = getController().getWindow();
surface.clear(sf::Color::Black);
surface.draw(sfml);
text.setFont(manual);
text.setPosition(sf::Vector2f(screenMid, 200));
text.setFillColor(sf::Color::White);
text.setString(info);
setOrigin(text, 0.5f, 0);
surface.draw(text);
text.setFont(font);
text.setFillColor(sf::Color::Black);
setOrigin(text, 0.5f, 0.5f);
goback.draw(surface, text, screenMid, screenBottom - 40);
}
void onEnd() override {
}
~AboutScene() { delete btn; }
};