]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fight stuff
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 26 Oct 2017 19:54:44 +0000 (15:54 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 26 Oct 2017 19:54:44 +0000 (15:54 -0400)
assets/music/fight.ogg [new file with mode: 0644]
assets/sounds/badOuch.wav [new file with mode: 0644]
config/items.xml
include/components/health.hpp
include/components/sprite.hpp
main.cpp
src/attack.cpp
src/world.cpp
xml/!town2.xml
xml/entities.xml
xml/fight.xml [new file with mode: 0644]

diff --git a/assets/music/fight.ogg b/assets/music/fight.ogg
new file mode 100644 (file)
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 (file)
index 0000000..c799f9e
Binary files /dev/null and b/assets/sounds/badOuch.wav differ
index a70996a3495b84c3ad932e1f698a76d8b9f70981..c613c4e77f34e6119d56d489837efc25429cba97 100644 (file)
@@ -36,7 +36,7 @@
                end
        </attack>
 </item>
-<item name="Hunters Bow" type="Bow" drawOffset="5,16" maxStackSize="1" sprite="assets/items/bow.png" cooldown="600">
+<item name="Hunters Bow" type="Bow" drawOffset="5,16" maxStackSize="1" sound="assets/sounds/shortSwing.wav" sprite="assets/items/bow.png" cooldown="600">
        <attack effect="assets/effects/starAttack.gif">
                effect = function()
                        flash(255, 0, 255)
index eacaaa52eb0348710eb2febe8b24e903accb3e5f..f0b8e6b3ecb6abe3705a6b12ba90537894c894e3 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "base.hpp"
 
+#include <SDL2/SDL_mixer.h>
+
 /**
  * @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;
        }
 };
 
index 0617620463107b93e9892b9661b8e8f0df82a128..33755b230cd5f33ab56444703d347af1910e2321 100644 (file)
@@ -56,6 +56,7 @@ struct Sprite : public Component {
                auto frames = developFrame(def);
                if (!frames.empty())
                        sprite = frames.at(0);
+               faceLeft = false;
        }
 
        Frame sprite;
index fad13155ba9f3f46898d9b7811309260919ae3d7..ce1505d0ccf4f31a22532d85f2bfc74e29574e2b 100644 (file)
--- 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<std::string> xmlFiles;
        if (getdir(std::string("./" + game::config::xmlFolder), xmlFiles))
index cf2f6277ec3c5315be4f5d6f290dd856a25b733c..41fb77c8057e37188d6695a58cfdf856de700f86 100644 (file)
@@ -51,7 +51,10 @@ namespace lua {
 
        int damage(lua_State* state) {
                float d = lua_tonumber(state, 1);
-               entity->component<Health>()->health -= d;
+               auto h = entity->component<Health>();
+               h->health -= d;
+               if (h->ouch != nullptr)
+                       Mix_PlayChannel(0, h->ouch, 0);
                return 0;
        }
 }
index e54a7eca46dd11152e096aad975785bb93d3413f..0cfa7251ab589b3a846f23ff61f34010bd5d26e4 100644 (file)
@@ -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,
index fcdf507c4a9a419bac4ac80168a9cebe00ef103b..cc1953ff66f92e96bb8255c021f5f68e017271e2 100644 (file)
                <layer path="bg/dirt.png"/>
                <layer path="bg/grass.png"/>
        </style>
-       <generation width="1000"/>
+       <generation>
+               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
+       </generation>
        <time>6000</time>
        <link left="!town.xml"/>
 </World>
index b95b5a6c8a951bdc03665ee736f7002f5e7454a6..1759f1f4948ff0e8027dde58e83cdc5d4f1088d2 100644 (file)
@@ -10,7 +10,7 @@
        </Sprite>
        <Direction />
        <Solid />
-       <Illuminate radius="100" />
+       <Illuminate radius="75" />
        <Wander>
                countdown = 0
 
@@ -89,7 +89,7 @@
 </npc>
 
 <skirl>
-       <Position value="300.0,100.0" />
+       <Position />
        <Visible value="0.2" />
        <Sprite>
                <frame>
@@ -97,7 +97,7 @@
                </frame>
        </Sprite>
        <Direction />
-       <Health value="50" />
+       <Health value="200" ouch="assets/sounds/badOuch.wav" />
        <Solid />
        <Physics />
        <Name value="SKIRL" />
                end
 
                hostile = function()
-
+                       
                end
        </Wander>
        <Aggro/>
 </chest>
 
 <trigger>
-       <Position value="200.0,100.0" />
-       <Direction />
-       <Solid value="1.0,1.0" /> 
+       <Position value="0.0,100.0" />
+       <Solid value="1.0,500.0" /> 
        <Trigger />
 </trigger>
diff --git a/xml/fight.xml b/xml/fight.xml
new file mode 100644 (file)
index 0000000..aaf30cd
--- /dev/null
@@ -0,0 +1,37 @@
+<include file="entities.xml" />
+<World>
+       <style bgm="assets/music/fight.ogg" folder="assets/style/classic/">
+               <layer path="bg/bg.png"/>
+               <layer path="bg/bgFarMountain.png"/>
+               <layer path="bg/forestTileFar.png"/>
+               <layer path="bg/forestTileBack.png"/>
+               <layer path="bg/forestTileMid.png"/>
+               <layer path="bg/forestTileFront.png"/>
+               <layer path="bg/dirt.png"/>
+               <layer path="bg/grass.png"/>
+       </style>
+       <generation>
+               x = 0
+
+               ground = function()
+                       if (x == 240) then
+                               height = -1
+                       else
+                               height = 1 / math.cos((x / 1.19 - 100) * 3.14 / 180)
+                               if (height &lt; 0 or height &gt; 800) then
+                                       height = 800
+                               else
+                                       height = height + 60
+                               end
+                       end
+
+                       x = x + 1
+               end
+
+               grass = function()
+                       height = math.random(2, 5)
+               end
+       </generation>
+       <time>6000</time>
+       <skirl />
+</World>