-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartScreen.cpp
More file actions
90 lines (75 loc) · 2.43 KB
/
StartScreen.cpp
File metadata and controls
90 lines (75 loc) · 2.43 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
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
#include "StartScreen.h"
#include <memory>
StartScreen::StartScreen() :
mFont(FontManager::GetFont()),
mTitle(TITLE, mFont, 100),
mTitleShadow(),
mRunning(),
mRunningStr("TETRIS++ is a clone Tetris-game created Alex Pajitnov in 1984. "
"Also this clone based on some ideas which represented by A.Banzhaf and E.Kappel "
"in their Tetris clone - Professional TET42. "
"It must be said that AI ChatGPT provided assistance in the creation of the game. "
"Thanks for reading. Enjoy the game!"),
mSpeedRunningStr(200.0f),
mClockRunningStr(),
mSize({ 300, 60 }),
mPositionSingle({ HALF_WIDTH - 150.f, HALF_HEIGHT + (HALF_HEIGHT / 2) - 135.f }),
mPositionCamp({ HALF_WIDTH - 150.f, HALF_HEIGHT + (HALF_HEIGHT / 2) + 35.f }),
mButtonSingle(std::make_unique<Button2>(mSize, mPositionSingle, "Single Game", mFont)),
mButtonCampaign(std::make_unique<Button2>(mSize, mPositionCamp, "Campaign", mFont)),
mIsChoiceDone(false),
mChoice("")
{
// title
mTitle.setFillColor(titleColor);
float textMiddleWidth = mTitle.getLocalBounds().width / 2;
float textHeight = mTitle.getLocalBounds().height;
mTitle.setPosition(HALF_WIDTH - textMiddleWidth, HALF_HEIGHT - textHeight - (HEIGHT / 10));
mTitleShadow = mTitle;
mTitleShadow.setFillColor(shadowTitleColor);
mTitleShadow.move(4, 4);
// running string
mRunning.setString(mRunningStr);
mRunning.setFont(mFont);
mRunning.setCharacterSize(30);
mRunning.setFillColor(buttonActiveColor);
sf::Vector2f startPosition(WIDTH, 900);
mRunning.setPosition(startPosition);
}
void StartScreen::eventHandler(sf::RenderWindow& window, const sf::Event& event)
{
mButtonSingle->update(window);
mButtonCampaign->update(window);
if (mButtonSingle->isClicked())
{
mChoice = "single";
mIsChoiceDone = true;
}
if (mButtonCampaign->isClicked())
{
mChoice = "camp";
mIsChoiceDone = true;
}
if (event.type == sf::Event::Closed)
{
mChoice = "exit";
mIsChoiceDone = true;
}
}
void StartScreen::draw(sf::RenderWindow& window)
{
window.clear(backgroundColor);
window.draw(mTitleShadow);
window.draw(mTitle);
mButtonSingle->draw(window);
mButtonCampaign->draw(window);
// draw running string
float deltaTime = mClockRunningStr.restart().asSeconds();
sf::Vector2f position = mRunning.getPosition();
position.x -= mSpeedRunningStr * deltaTime;
if (position.x + mRunning.getLocalBounds().width < 0) {
position.x = window.getSize().x;
}
mRunning.setPosition(position);
window.draw(mRunning);
}