-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.cpp
More file actions
52 lines (44 loc) · 2.09 KB
/
interface.cpp
File metadata and controls
52 lines (44 loc) · 2.09 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
#include "interface.h"
Interface::Interface(sf::Font newFont, sf::IntRect size) :
font(newFont), currentEnergy(0), energy(font, "0", sf::Color(255, 255, 255, 128), 75.f), minus(font, "-0", sf::Color(255, 255, 255, 128), 75.f),
progress({100.f, 20.f}), bar({100.f, 20.f}), shoot(font, "ЛКМ - стрелять", sf::Color(255, 255, 255, 128), 40.f), store(font, "ПКМ - купить автономного бота-собирателя за 10", sf::Color(255, 255, 255, 128), 40.f)
{
energy.setPosition({0.f, 10.f});
minus.setPosition(sf::Vector2f(0.f, energy.getBounds().position.y + energy.getBounds().size.y));
progress.setFillColor(sf::Color(255, 255, 255, 128));
bar.setFillColor(sf::Color::Transparent);
bar.setOutlineColor(sf::Color(255, 255, 255, 196));
bar.setOutlineThickness(5.f);
progress.setPosition(sf::Vector2f(20.f, energy.getBounds().position.y + energy.getBounds().size.y + minus.getBounds().size.y + 20.f));
bar.setPosition(sf::Vector2f(20.f, energy.getBounds().position.y + energy.getBounds().size.y + minus.getBounds().size.y + 20.f));
store.setPosition(sf::Vector2f(size.size) - store.getBounds().size);
shoot.setPosition(sf::Vector2f(size.size) - shoot.getBounds().size - sf::Vector2f(0.f, store.getBounds().size.y + 10.f));
}
void Interface::setEnergy(long long newEnergy)
{
currentEnergy = newEnergy;
}
void Interface::update(float prog)
{
progress.setSize({100 - prog * 100.f, 20.f});
if (std::stoll(energy.getString()) == currentEnergy) {
return ;
}
energy.setString(" " + std::to_string(std::stoll(energy.getString()) + ((currentEnergy - std::stoll(energy.getString())) > 0 ? 1 : -1)));
}
void Interface::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
sf::View buf = target.getView();
target.setView(target.getDefaultView());
target.draw(energy);
target.draw(minus);
target.draw(progress);
target.draw(bar);
target.draw(shoot);
target.draw(store);
target.setView(buf);
}
void Interface::setMinus(int newMinus)
{
minus.setString(" -" + std::to_string(newMinus));
}