-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitGameStart.cpp
More file actions
132 lines (108 loc) · 3.97 KB
/
InitGameStart.cpp
File metadata and controls
132 lines (108 loc) · 3.97 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
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
#include "pch.h"
#include "InitGameStart.h"
void InitGameStart::initVariables() {
this->videoMode = sf::VideoMode::getDesktopMode();
this->font.loadFromFile("Fonts/metropolis/Metropolis-SemiBold.otf");
this->endGame = false;
this->playGame = false;
this->returnButtonClicked = false;
this->isUpdating = true;
this->isRendering = true;
this->userKingdomName = "";
}
void InitGameStart::initBackground() {
this->buttonBackground.setSize(sf::Vector2f(static_cast<float>(this->videoMode.width) / 4.f, static_cast<float>(this->videoMode.height)));
this->buttonBackground.setFillColor(sf::Color(0, 0, 0, 150));
this->buttonBackground.setPosition(static_cast<float>(this->videoMode.width) / 4.f + this->buttonBackground.getGlobalBounds().width / 2.f, 0);
}
void InitGameStart::initButtons() {
this->chooseKingdomButton = new InteractiveButton(
sf::Vector2f(this->buttonBackground.getGlobalBounds().width + this->buttonBackground.getGlobalBounds().width / 2.f, this->buttonBackground.getLocalBounds().height / 2.f - 100.f),
sf::Vector2f(this->buttonBackground.getGlobalBounds().width, 50.0f),
"Enter Kingdom Name",
"Fonts/metropolis/Metropolis-SemiBold.otf", sf::Color(0, 0, 0, 0),
sf::Color(0, 0, 0, 150)
);
this->playButton = new Button(
sf::Vector2f(this->buttonBackground.getGlobalBounds().width + this->buttonBackground.getGlobalBounds().width / 2.f, this->buttonBackground.getLocalBounds().height / 2.f - 50.f),
sf::Vector2f(this->buttonBackground.getGlobalBounds().width, 50.f),
"Play Game",
this->font,
sf::Color(0, 0, 0, 0),
sf::Color(0, 0, 0, 150)
);
this->returnButton = new Button(
sf::Vector2f(this->buttonBackground.getGlobalBounds().width + this->buttonBackground.getGlobalBounds().width / 2.f, this->buttonBackground.getLocalBounds().height / 2.f + 50.f),
sf::Vector2f(this->buttonBackground.getGlobalBounds().width, 50.f),
"Return to Main Menu",
this->font,
sf::Color(0, 0, 0, 0),
sf::Color(0, 0, 0, 150)
);
}
void InitGameStart::deleteButtons() const {
delete this->chooseKingdomButton;
delete this->playButton;
delete this->returnButton;
}
InitGameStart::InitGameStart() {
this->initVariables();
this->initBackground();
this->initButtons();
}
InitGameStart::~InitGameStart() {
this->deleteButtons();
}
bool InitGameStart::getEndGame() const {
return this->endGame;
}
bool InitGameStart::getPlayGame() const {
return this->playGame;
}
bool InitGameStart::getReturnButtonClicked() const {
return this->returnButtonClicked;
}
void InitGameStart::setReturnButtonClicked(const bool clicked) {
this->returnButtonClicked = clicked;
}
void InitGameStart::setPlayGame(bool play) {
this->playGame = play;
}
void InitGameStart::setEvt(const sf::Event &evt) {
this->ev = evt;
}
void InitGameStart::stopRender() {
this->isRendering = false;
}
void InitGameStart::stopUpdate() {
this->isUpdating = false;
}
void InitGameStart::update() {
if (isUpdating) {
const sf::Vector2i mousePos = sf::Mouse::getPosition();
this->chooseKingdomButton->update(mousePos, ev);
this->playButton->update(mousePos);
if (this->playButton->isClicked(mousePos)) {
this->userKingdomName = chooseKingdomButton->getUserInput(); // Get user input for kingdom name
this->playGame = true;
}
this->returnButton->update(mousePos);
if (this->returnButton->isClicked(mousePos)) {
this->returnButtonClicked = true;
}
}
}
void InitGameStart::render(sf::RenderTarget& target) const {
if (isRendering) {
target.draw(this->buttonBackground);
this->chooseKingdomButton->draw(target);
this->playButton->draw(target);
this->returnButton->draw(target);
}
}
void InitGameStart::startRender() {
this->isRendering = true;
}
void InitGameStart::startUpdate() {
this->isUpdating = true;
}