Now have a timer going with some fancy buttons. Next step a pomodoro time that counts down and if you don't finish your task in that time you take big damage.
This commit is contained in:
parent
47c9cb719e
commit
fff4e0fbee
2 changed files with 22 additions and 7 deletions
|
@ -79,10 +79,11 @@ void SFMLBackend::handle_events() {
|
|||
case sf::Event::MouseButtonPressed: {
|
||||
// rect::contains(x,y) for if mouse is in the button rect
|
||||
sf::Event::MouseButtonEvent btn = event.mouseButton;
|
||||
bool stop_clicked = stop_button.getGlobalBounds().contains(btn.x, btn.y);
|
||||
bool start_clicked = start_button.getGlobalBounds().contains(btn.x, btn.y);
|
||||
|
||||
fmt::println("BUTTON: start={}, stop={}", start_clicked, stop_clicked);
|
||||
if(stop_button.getGlobalBounds().contains(btn.x, btn.y)) {
|
||||
buttons = Button::STOP;
|
||||
} else if(start_button.getGlobalBounds().contains(btn.x, btn.y)) {
|
||||
buttons = Button::START;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -148,9 +149,17 @@ void SFMLBackend::update_entities() {
|
|||
game.streak, game.deaths);
|
||||
write_text(X_ROWS/4 + 5, 2, status);
|
||||
|
||||
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
|
||||
string time = fmt::format("{:%r}", now);
|
||||
write_text(2, 14, time, 2.0f);
|
||||
if(buttons == Button::START) {
|
||||
// better thing here please
|
||||
} else if(buttons == Button::STOP) {
|
||||
clock_start = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
auto elapsed_time = std::chrono::system_clock::now() - clock_start;
|
||||
|
||||
string time = format("{:%H:%M:%OS}", elapsed_time);
|
||||
write_text(7, 14, time, 2.0f);
|
||||
|
||||
|
||||
stop_button.setPosition(translate(27, 15));
|
||||
window.draw(start_button);
|
||||
|
|
|
@ -29,6 +29,10 @@ constexpr Value BOX_OUTLINE = Value::MID;
|
|||
constexpr int BOX_THICKNESS=10;
|
||||
constexpr Value BOX_FILL = Value::TRANSPARENT;
|
||||
|
||||
enum class Button {
|
||||
NONE, START, STOP
|
||||
};
|
||||
|
||||
class SoundQuip {
|
||||
public:
|
||||
sf::Sound sound;
|
||||
|
@ -51,6 +55,8 @@ class SFMLBackend {
|
|||
sf::Texture stop_texture;
|
||||
sf::Sprite start_button;
|
||||
sf::Texture start_texture;
|
||||
std::chrono::time_point<std::chrono::system_clock> clock_start;
|
||||
Button buttons = Button::NONE;
|
||||
int hit_points = 50;
|
||||
sf::Font font;
|
||||
GameEngine &game;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue