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.

master
Zed A. Shaw 10 months ago
parent 47c9cb719e
commit fff4e0fbee
  1. 23
      sfmlbackend.cpp
  2. 6
      sfmlbackend.hpp

@ -79,10 +79,11 @@ void SFMLBackend::handle_events() {
case sf::Event::MouseButtonPressed: { case sf::Event::MouseButtonPressed: {
// rect::contains(x,y) for if mouse is in the button rect // rect::contains(x,y) for if mouse is in the button rect
sf::Event::MouseButtonEvent btn = event.mouseButton; sf::Event::MouseButtonEvent btn = event.mouseButton;
bool stop_clicked = stop_button.getGlobalBounds().contains(btn.x, btn.y); if(stop_button.getGlobalBounds().contains(btn.x, btn.y)) {
bool start_clicked = start_button.getGlobalBounds().contains(btn.x, btn.y); buttons = Button::STOP;
} else if(start_button.getGlobalBounds().contains(btn.x, btn.y)) {
fmt::println("BUTTON: start={}, stop={}", start_clicked, stop_clicked); buttons = Button::START;
}
break; break;
} }
default: default:
@ -148,9 +149,17 @@ void SFMLBackend::update_entities() {
game.streak, game.deaths); game.streak, game.deaths);
write_text(X_ROWS/4 + 5, 2, status); write_text(X_ROWS/4 + 5, 2, status);
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now(); if(buttons == Button::START) {
string time = fmt::format("{:%r}", now); // better thing here please
write_text(2, 14, time, 2.0f); } 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)); stop_button.setPosition(translate(27, 15));
window.draw(start_button); window.draw(start_button);

@ -29,6 +29,10 @@ constexpr Value BOX_OUTLINE = Value::MID;
constexpr int BOX_THICKNESS=10; constexpr int BOX_THICKNESS=10;
constexpr Value BOX_FILL = Value::TRANSPARENT; constexpr Value BOX_FILL = Value::TRANSPARENT;
enum class Button {
NONE, START, STOP
};
class SoundQuip { class SoundQuip {
public: public:
sf::Sound sound; sf::Sound sound;
@ -51,6 +55,8 @@ class SFMLBackend {
sf::Texture stop_texture; sf::Texture stop_texture;
sf::Sprite start_button; sf::Sprite start_button;
sf::Texture start_texture; sf::Texture start_texture;
std::chrono::time_point<std::chrono::system_clock> clock_start;
Button buttons = Button::NONE;
int hit_points = 50; int hit_points = 50;
sf::Font font; sf::Font font;
GameEngine &game; GameEngine &game;

Loading…
Cancel
Save