diff --git a/assets/build_failed.png b/assets/build_failed.png new file mode 100644 index 0000000..6dcb9ad Binary files /dev/null and b/assets/build_failed.png differ diff --git a/assets/build_success.png b/assets/build_success.png index c7985ed..30d1511 100644 Binary files a/assets/build_success.png and b/assets/build_success.png differ diff --git a/assets/building.png b/assets/building.png new file mode 100644 index 0000000..f89c12b Binary files /dev/null and b/assets/building.png differ diff --git a/assets/you_died.png b/assets/you_died.png new file mode 100644 index 0000000..86d55a6 Binary files /dev/null and b/assets/you_died.png differ diff --git a/builder.cpp b/builder.cpp index d78344b..f670945 100644 --- a/builder.cpp +++ b/builder.cpp @@ -80,7 +80,7 @@ void Builder::BUILDING(BuildEvent ev) { if(rc == 0) { game.event(GameEvent::BUILD_SUCCESS); - gui.build_works(); + gui.build_success(); } else { game.event(GameEvent::BUILD_FAILED); gui.build_failed(!game.is_dead(), build_cmd); diff --git a/escape_turings_tarpit.cpp b/escape_turings_tarpit.cpp index 54afc50..2e45105 100644 --- a/escape_turings_tarpit.cpp +++ b/escape_turings_tarpit.cpp @@ -4,16 +4,16 @@ int main(int argc, char *argv[]) { - GUI gui; GameEngine game{100}; auto backend = SFMLBackend(game); + GUI gui(backend); auto builder = Builder(gui, game); backend.startup(); while(backend.is_open()) { builder.event(BuildEvent::GO); - gui.main_loop(backend); + gui.main_loop(); } builder.event(BuildEvent::QUIT); diff --git a/fsm.hpp b/fsm.hpp index 5898ea4..1dbebc7 100644 --- a/fsm.hpp +++ b/fsm.hpp @@ -11,7 +11,7 @@ template class DeadSimpleFSM { protected: - // BUG: don't put this in your class because state() won't work + // BUG: don't put this in your class because state() won't wor S _state = S::START; public: diff --git a/gui.cpp b/gui.cpp index 06346ec..8f938bb 100644 --- a/gui.cpp +++ b/gui.cpp @@ -17,13 +17,13 @@ using namespace fmt; using namespace nlohmann; namespace fs = std::filesystem; -GUI::GUI() { +GUI::GUI(SFMLBackend &backend) : gui(backend) { std::ifstream infile(".tarpit.json"); json data = json::parse(infile); // json load the config file you_died_sound.load(data, "you_died"); - build_works_sound.load(data, "build_works"); + build_success_sound.load(data, "build_success"); build_failed_sound.load(data, "build_failed"); building_sound.load(data, "building", true); } @@ -33,19 +33,21 @@ void GUI::output(const string msg) { std::cout << msg << std::endl; } -void GUI::main_loop(SFMLBackend &gui) { +void GUI::main_loop() { gui.handle_events(); gui.update_entities(); gui.update_log(_lines); } -void GUI::build_works() { +void GUI::build_success() { + gui.change_face("build_success"); building_sound.stop(); - build_works_sound.play(); + build_success_sound.play(); output("BUILD FINISHED!"); } void GUI::build_failed(bool play_sound, const string &command) { + gui.change_face("build_failed"); building_sound.stop(); if(play_sound) { @@ -56,6 +58,7 @@ void GUI::build_failed(bool play_sound, const string &command) { } void GUI::you_died() { + gui.change_face("you_died"); building_sound.stop(); you_died_sound.play(); output("!!!! YOU DIED! !!!! Learn to code luser."); @@ -63,6 +66,7 @@ void GUI::you_died() { } void GUI::building() { + gui.change_face("building"); output("############# START ############"); output(">>>> Will it Build?"); building_sound.play(); diff --git a/gui.hpp b/gui.hpp index acf4e24..74ba3fc 100644 --- a/gui.hpp +++ b/gui.hpp @@ -12,22 +12,23 @@ class GUI { std::vector _lines; SoundQuip you_died_sound; - SoundQuip build_works_sound; + SoundQuip build_success_sound; SoundQuip build_failed_sound; SoundQuip building_sound; + SFMLBackend &gui; public: - GUI(); + GUI(SFMLBackend &backend); // prevent copy GUI(GUI &g) = delete; void output(const string msg); - void main_loop(SFMLBackend &backend); + void main_loop(); - void build_works(); + void build_success(); void build_failed(bool play_sound, const string &command); void you_died(); void building(); diff --git a/sfmlbackend.cpp b/sfmlbackend.cpp index 0d836b0..255755c 100644 --- a/sfmlbackend.cpp +++ b/sfmlbackend.cpp @@ -1,6 +1,7 @@ #define _USE_MATH_DEFINES #include #include +#include #include #include #include @@ -70,13 +71,9 @@ void SFMLBackend::handle_events() { break; case sf::Event::KeyPressed: if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { - if(show_build_log) { - window_active_out = false; - } else { - window.close(); - } + window.close(); } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { - window_active_out = !window_active_out; + fmt::println("STOP THE CLOCK"); } break; case sf::Event::MouseButtonPressed: { @@ -128,7 +125,7 @@ sf::RectangleShape SFMLBackend::box(int x, int y, int width, int height, void SFMLBackend::update_entities() { window.clear(); - sf::RectangleShape face_box = box(2, 2, X_ROWS/4, Y_LINES/2); + sf::RectangleShape face_box = box(2, 2, X_ROWS/4, Y_LINES/2, Value::DARK_DARK); face_sprite.setPosition(translate(2,2)); window.draw(face_sprite); @@ -148,8 +145,8 @@ void SFMLBackend::update_entities() { 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)); + std::chrono::time_point now = std::chrono::system_clock::now(); + string time = fmt::format("{:%r}", now); write_text(2, 14, time, 2.0f); sf::RectangleShape start_btn = box(27, 16, 8, 3, Value::DARK_MID); @@ -159,23 +156,28 @@ void SFMLBackend::update_entities() { write_text(39, 16, "DONE", 1.0f); Window_update(); - - show_build_log = window_active_out; } -SFMLBackend::SFMLBackend(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g) -{ +void SFMLBackend::change_face(const string name) { std::ifstream infile(".tarpit.json"); json data = json::parse(infile); - auto audio = data["images"]; - json::string_t file_name = audio["build_works"].template get(); + auto images = data["images"]; + json::string_t file_name = images[name].template get(); face_texture.loadFromFile(file_name); face_sprite.setTexture(face_texture); } +SFMLBackend::SFMLBackend(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g) +{ + change_face("building"); +} + + + + /* - * This makes my sould hurt. Make it stop. + * This makes my soul hurt. Make it stop. * * TODO: Make this more efficient, and don't display * more than 10 or so errors since more than that is diff --git a/sfmlbackend.hpp b/sfmlbackend.hpp index 545870f..77f8e46 100644 --- a/sfmlbackend.hpp +++ b/sfmlbackend.hpp @@ -45,12 +45,8 @@ public: class SFMLBackend { sf::ContextSettings settings; sf::RenderWindow window; - sf::Clock clock; - sf::Clock deltaClock; sf::Sprite face_sprite; sf::Texture face_texture; - bool window_active_out = false; - bool show_build_log = false; int hit_points = 50; sf::Font font; GameEngine &game; @@ -67,6 +63,7 @@ public: bool is_open(); void shutdown(); + void change_face(const string name); void handle_events(); void update_entities(); void update_log(std::vector &lines); diff --git a/status.txt b/status.txt index d9c4c58..78321ad 100644 --- a/status.txt +++ b/status.txt @@ -6,10 +6,10 @@ BUGS: 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. - -* Convert buttons to sprites. -* Mouse events to the GUI. +* chrono::time_point is probably what we need but need to know where to put it for the timeout events and soo on. +* Make some button graphics and use sprites, or see if you can do a drawn sprite. * sf::Rect::contains(mouse.x, mouse.y) will say if the mouse is inside the sprite rect. +* Redo the images of me so they're correctly cropped. NOTES: