From 95cd84b09df2a86516def98bf328a25e7d14ea88 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 16 Sep 2024 17:24:02 -0400 Subject: [PATCH] Get the build fail to actually play and keep the building sound looping until the build is done. --- builder.cpp | 2 +- fsm.hpp | 2 +- game_engine.cpp | 3 ++- game_engine.hpp | 1 - gui.cpp | 2 +- sfmlbackend.cpp | 3 ++- sfmlbackend.hpp | 2 +- status.txt | 2 -- 8 files changed, 8 insertions(+), 9 deletions(-) diff --git a/builder.cpp b/builder.cpp index 214929b..d78344b 100644 --- a/builder.cpp +++ b/builder.cpp @@ -87,7 +87,6 @@ void Builder::BUILDING(BuildEvent ev) { } build_out = NULL; - game.event(GameEvent::BUILD_DONE); state(BuildState::DONE); } else { auto m = parse_line(line); @@ -171,6 +170,7 @@ void Builder::DONE(BuildEvent ev) { gui.you_died(); } + game.event(GameEvent::BUILD_DONE); listener->reset_state(); gui.output("^^^^^^^^^^^ END ^^^^^^^^^^^"); state(BuildState::WAITING); 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 3bf573b..0e72477 100644 --- a/game_engine.cpp +++ b/game_engine.cpp @@ -3,6 +3,7 @@ #include #include #include +#define FSM_DEBUG 1 #include "game_engine.hpp" #include #include "dbc.hpp" @@ -14,7 +15,7 @@ using namespace std; GameEngine::GameEngine(int hp) : starting_hp(hp) { hit_points = max_hp(); -}; +} int GameEngine::determine_damage(string &type) { try { diff --git a/game_engine.hpp b/game_engine.hpp index 834ccab..1beeef5 100644 --- a/game_engine.hpp +++ b/game_engine.hpp @@ -13,7 +13,6 @@ enum class GameState { START, IDLE, IN_ROUND, DEAD, SUCCESS, FAILURE }; - enum class GameEvent { BUILD_START, BUILD_SUCCESS, BUILD_DONE, BUILD_FAILED, HIT diff --git a/gui.cpp b/gui.cpp index 301dce0..d5c8d54 100644 --- a/gui.cpp +++ b/gui.cpp @@ -25,7 +25,7 @@ GUI::GUI() { you_died_sound.load(data, "you_died"); build_works_sound.load(data, "build_works"); build_failed_sound.load(data, "build_failed"); - building_sound.load(data, "building"); + building_sound.load(data, "building", true); } void GUI::output(const string msg) { diff --git a/sfmlbackend.cpp b/sfmlbackend.cpp index 5c2c0f9..163c54c 100644 --- a/sfmlbackend.cpp +++ b/sfmlbackend.cpp @@ -17,7 +17,7 @@ using namespace nlohmann; using namespace ImGui; using std::string; -void SoundQuip::load(json &data, const char *file_key) { +void SoundQuip::load(json &data, const char *file_key, bool loop) { auto audio = data["audio"]; json::string_t file_name = audio[file_key].template get(); @@ -26,6 +26,7 @@ void SoundQuip::load(json &data, const char *file_key) { } sound.setBuffer(buffer); + sound.setLoop(loop); } void SoundQuip::play() { diff --git a/sfmlbackend.hpp b/sfmlbackend.hpp index 7ddbb3c..0002a3a 100644 --- a/sfmlbackend.hpp +++ b/sfmlbackend.hpp @@ -25,7 +25,7 @@ public: SoundQuip() {}; - void load(nlohmann::json &data, const char *in_file); + void load(nlohmann::json &data, const char *file_key, bool loop=false); void play(); void stop(); }; diff --git a/status.txt b/status.txt index ab37297..df0201b 100644 --- a/status.txt +++ b/status.txt @@ -5,8 +5,6 @@ BUGS: * BUG: doesn't play you_died sound. TODO: -* Rewrite dbc.hpp to actually work. - * 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. * Track the deaths.