diff --git a/fsm.hpp b/fsm.hpp index 5898ea4..28dcddd 100644 --- a/fsm.hpp +++ b/fsm.hpp @@ -18,7 +18,7 @@ public: template void event(E event, Types... args); - void state(S next_state) { + void state(S next_state) _state = next_state; } diff --git a/game_engine.cpp b/game_engine.cpp index 0e72477..72f46be 100644 --- a/game_engine.cpp +++ b/game_engine.cpp @@ -95,6 +95,7 @@ void GameEngine::IN_ROUND(GameEvent ev, string &hit_type) { void GameEngine::DEAD(GameEvent ev) { if(ev == GameEvent::BUILD_DONE) { + deaths++; reset(); state(GameState::FAILURE); FAILURE(ev); diff --git a/game_engine.hpp b/game_engine.hpp index 1beeef5..ce39c4e 100644 --- a/game_engine.hpp +++ b/game_engine.hpp @@ -35,6 +35,7 @@ class GameEngine : DeadSimpleFSM { int hit_points = 0; int hits_taken = 0; int rounds = 0; + int deaths = 0; int streak = 0; float hp_bonus = 1.0f; bool free_death = false; diff --git a/sfmlbackend.cpp b/sfmlbackend.cpp index 163c54c..359634a 100644 --- a/sfmlbackend.cpp +++ b/sfmlbackend.cpp @@ -1,8 +1,7 @@ -#include "imgui.h" -#include "imgui-SFML.h" #define _USE_MATH_DEFINES #include #include +#include #include #include #include @@ -14,7 +13,6 @@ using namespace fmt; using namespace nlohmann; -using namespace ImGui; using std::string; void SoundQuip::load(json &data, const char *file_key, bool loop) { @@ -37,34 +35,7 @@ void SoundQuip::stop() { sound.stop(); } -void SFMLBackend::ImGui_setup() { - bool res = SFML::Init(window); - fmt::println("IMGUI returned {}", res); -} - -void SFMLBackend::ImGui_update() { - sf::Vector2u size = window.getSize(); - - SFML::Update(window, deltaClock.restart()); - - SetNextWindowPos(ImVec2(0, 0)); - SetNextWindowSize(ImVec2(size.x, size.y)); - - Begin("Build Status", &window_active_out); - - TextColored(ImVec4(1,1,0,1), "Build Log"); - BeginChild("Scrolling"); - for(string &line : log) { - TextWrapped(line.c_str()); - } - EndChild(); - End(); -} - void SFMLBackend::Window_update() { - if(show_build_log) { - SFML::Render(window); - } window.display(); } @@ -73,10 +44,6 @@ void SFMLBackend::handle_events() { // is this a main event loop while (window.pollEvent(event)) { - if(show_build_log) { - SFML::ProcessEvent(window, event); - } - switch(event.type) { case sf::Event::Closed: fmt::print("Exiting...\n"); @@ -110,12 +77,12 @@ sf::Vector2f translate(int x, int y) { } -void SFMLBackend::write_text(int x, int y, string content) { +void SFMLBackend::write_text(int x, int y, string content, float size_mult) { sf::Vector2f position = translate(x,y); sf::Text text; text.setFont(font); text.setString(content); - text.setCharacterSize(TEXT_SIZE); + text.setCharacterSize(TEXT_SIZE * size_mult); text.setFillColor(sf::Color(100, 250, 50)); text.setPosition(position); window.draw(text); @@ -125,14 +92,20 @@ void SFMLBackend::update_entities() { window.clear(); sf::RectangleShape face_box(translate(X_ROWS/4, Y_LINES/2)); - face_box.setPosition(translate(X_ROWS/3+2,2)); + face_box.setPosition(translate(2,2)); face_box.setOutlineColor(sf::Color(50, 200, 25)); face_box.setOutlineThickness(10); face_box.setFillColor(sf::Color(200, 250, 200)); window.draw(face_box); - constexpr int hp_box_len = 44; + sf::RectangleShape stats_box(translate(X_ROWS - X_ROWS/4 - 5, Y_LINES/2)); + stats_box.setPosition(translate(X_ROWS/4 + 4, 2)); + stats_box.setOutlineColor(sf::Color(50, 200, 25)); + stats_box.setOutlineThickness(10); + stats_box.setFillColor(sf::Color(0, 0, 0)); + window.draw(stats_box); + constexpr int hp_box_len = 45; int current_hp = (float(game.hit_points) / float(game.starting_hp)) * float(hp_box_len); sf::RectangleShape hp_bar(translate(current_hp,2)); @@ -147,12 +120,15 @@ void SFMLBackend::update_entities() { hp_box.setFillColor(sf::Color::Transparent); window.draw(hp_box); - string status = fmt::format("HP {} Rounds {} Streaks {} Deaths XXX", game.hit_points, game.rounds, game.streak); - write_text(2, 18, status); + string status = fmt::format("HP {}\nRounds {}\nStreaks {}\nDeaths {}", + game.hit_points, game.rounds, + game.streak, game.deaths); + write_text(X_ROWS/4 + 5, 2, status); + + std::time_t t = std::time(nullptr); + string time = fmt::format("{:%r}", fmt::localtime(t)); + write_text(X_ROWS/4+1, 14, time, 2.0f); - if(show_build_log) { - ImGui_update(); - } Window_update(); show_build_log = window_active_out; @@ -189,7 +165,6 @@ void SFMLBackend::startup() { window.setFramerateLimit(FPS); window.setVerticalSyncEnabled(true); - ImGui_setup(); } bool SFMLBackend::is_open() { @@ -197,5 +172,4 @@ bool SFMLBackend::is_open() { } void SFMLBackend::shutdown() { - SFML::Shutdown(); } diff --git a/sfmlbackend.hpp b/sfmlbackend.hpp index 0002a3a..2374a44 100644 --- a/sfmlbackend.hpp +++ b/sfmlbackend.hpp @@ -59,9 +59,7 @@ public: void update_entities(); void update_log(std::vector &lines); - void write_text(int x, int y, string content); + void write_text(int x, int y, string content, float size_mult=1.0f); - void ImGui_setup(); - void ImGui_update(); void Window_update(); }; diff --git a/status.txt b/status.txt index df0201b..9caf4e7 100644 --- a/status.txt +++ b/status.txt @@ -1,8 +1,6 @@ * Using that to redesign the starter UI. BUGS: -* BUG: lots of errors crash it -* BUG: doesn't play you_died sound. TODO: * Add a timer to the game engine so you can set a kind of pomodoro timer and if you don't meet the goal it costs you.