From 3ef0e74749373d4cfa2a9f8cda9b536b77d8b4cd Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 26 Oct 2017 15:54:44 -0400 Subject: fight stuff --- assets/music/fight.ogg | Bin 0 -> 2307159 bytes assets/sounds/badOuch.wav | Bin 0 -> 605274 bytes config/items.xml | 2 +- include/components/health.hpp | 8 ++++++++ include/components/sprite.hpp | 1 + main.cpp | 6 ++++++ src/attack.cpp | 5 ++++- src/world.cpp | 2 ++ xml/!town2.xml | 18 +++++++++++++++++- xml/entities.xml | 13 ++++++------- xml/fight.xml | 37 +++++++++++++++++++++++++++++++++++++ 11 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 assets/music/fight.ogg create mode 100644 assets/sounds/badOuch.wav create mode 100644 xml/fight.xml diff --git a/assets/music/fight.ogg b/assets/music/fight.ogg new file mode 100644 index 0000000..0d54702 Binary files /dev/null and b/assets/music/fight.ogg differ diff --git a/assets/sounds/badOuch.wav b/assets/sounds/badOuch.wav new file mode 100644 index 0000000..c799f9e Binary files /dev/null and b/assets/sounds/badOuch.wav differ diff --git a/config/items.xml b/config/items.xml index a70996a..c613c4e 100644 --- a/config/items.xml +++ b/config/items.xml @@ -36,7 +36,7 @@ end - + effect = function() flash(255, 0, 255) diff --git a/include/components/health.hpp b/include/components/health.hpp index eacaaa5..f0b8e6b 100644 --- a/include/components/health.hpp +++ b/include/components/health.hpp @@ -3,6 +3,8 @@ #include "base.hpp" +#include + /** * @struct Health * @brief Gives and entity health and stuff. @@ -19,6 +21,7 @@ struct Health : public Component { int health; /**< The current amount of health */ int maxHealth; /**< The maximum amount of health */ + Mix_Chunk* ouch; /**< Sound made when attacked */ void fromXML(XMLElement* imp, XMLElement* def) final { (void)imp; @@ -27,6 +30,11 @@ struct Health : public Component { if (def->QueryIntAttribute("value", &health) != XML_NO_ERROR) health = 1; maxHealth = health; + auto o = def->Attribute("ouch"); + if (o != nullptr) + ouch = Mix_LoadWAV(o); + else + ouch = nullptr; } }; diff --git a/include/components/sprite.hpp b/include/components/sprite.hpp index 0617620..33755b2 100644 --- a/include/components/sprite.hpp +++ b/include/components/sprite.hpp @@ -56,6 +56,7 @@ struct Sprite : public Component { auto frames = developFrame(def); if (!frames.empty()) sprite = frames.at(0); + faceLeft = false; } Frame sprite; diff --git a/main.cpp b/main.cpp index fad1315..ce1505d 100644 --- a/main.cpp +++ b/main.cpp @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) { static bool worldReset = false, worldDontReallyRun = false; std::string worldActuallyUseThisXMLFile; + std::string worldActuallyUseThisXMLFolder; // handle command line args if (argc > 1) { @@ -53,6 +54,8 @@ int main(int argc, char *argv[]) worldDontReallyRun = true; else if (s == "--xml" || s == "-x") worldActuallyUseThisXMLFile = argv[i + 1]; + else if (s == "--folder" || s == "-f") + worldActuallyUseThisXMLFolder = argv[i + 1]; } } @@ -69,6 +72,9 @@ int main(int argc, char *argv[]) game::briceLoad(); game::briceUpdate(); + if (!worldActuallyUseThisXMLFolder.empty()) + game::config::xmlFolder = worldActuallyUseThisXMLFolder; + // read in all XML file names in the folder std::list xmlFiles; if (getdir(std::string("./" + game::config::xmlFolder), xmlFiles)) diff --git a/src/attack.cpp b/src/attack.cpp index cf2f627..41fb77c 100644 --- a/src/attack.cpp +++ b/src/attack.cpp @@ -51,7 +51,10 @@ namespace lua { int damage(lua_State* state) { float d = lua_tonumber(state, 1); - entity->component()->health -= d; + auto h = entity->component(); + h->health -= d; + if (h->ouch != nullptr) + Mix_PlayChannel(0, h->ouch, 0); return 0; } } diff --git a/src/world.cpp b/src/world.cpp index e54a7ec..0cfa725 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -69,6 +69,8 @@ void WorldSystem::generate(LuaScript& script) script("ground", {LuaVariable("height", h)}); if (h == -1.0f) break; + if (h > 5000) + h = 5000; script("grass", {LuaVariable("height", g[0])}); script("grass", {LuaVariable("height", g[1])}); world.data.push_back(WorldData {true, {g[0], g[1]}, h, diff --git a/xml/!town2.xml b/xml/!town2.xml index fcdf507..cc1953f 100644 --- a/xml/!town2.xml +++ b/xml/!town2.xml @@ -10,7 +10,23 @@ - + + x = 0 + + ground = function() + if (x == 600) then + height = -1 + else + height = 60 + math.random(0,6) / 2 + end + + x = x + 1 + end + + grass = function() + height = math.random(2, 5) + end + diff --git a/xml/entities.xml b/xml/entities.xml index b95b5a6..1759f1f 100644 --- a/xml/entities.xml +++ b/xml/entities.xml @@ -10,7 +10,7 @@ - + countdown = 0 @@ -89,7 +89,7 @@ - + @@ -97,7 +97,7 @@ - + @@ -113,7 +113,7 @@ end hostile = function() - + end @@ -226,8 +226,7 @@ - - - + + diff --git a/xml/fight.xml b/xml/fight.xml new file mode 100644 index 0000000..aaf30cd --- /dev/null +++ b/xml/fight.xml @@ -0,0 +1,37 @@ + + + + + x = 0 + + ground = function() + if (x == 240) then + height = -1 + else + height = 1 / math.cos((x / 1.19 - 100) * 3.14 / 180) + if (height < 0 or height > 800) then + height = 800 + else + height = height + 60 + end + end + + x = x + 1 + end + + grass = function() + height = math.random(2, 5) + end + + + + -- cgit v1.2.3