aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-10-26 15:54:44 -0400
committerClyne Sullivan <tullivan99@gmail.com>2017-10-26 15:54:44 -0400
commit3ef0e74749373d4cfa2a9f8cda9b536b77d8b4cd (patch)
treece5d7d350aab71114024d6add712df38928e2004
parentf785f17cdb286449e8d98be747213740172629c5 (diff)
fight stuff
-rw-r--r--assets/music/fight.oggbin0 -> 2307159 bytes
-rw-r--r--assets/sounds/badOuch.wavbin0 -> 605274 bytes
-rw-r--r--config/items.xml2
-rw-r--r--include/components/health.hpp8
-rw-r--r--include/components/sprite.hpp1
-rw-r--r--main.cpp6
-rw-r--r--src/attack.cpp5
-rw-r--r--src/world.cpp2
-rw-r--r--xml/!town2.xml18
-rw-r--r--xml/entities.xml13
-rw-r--r--xml/fight.xml37
11 files changed, 82 insertions, 10 deletions
diff --git a/assets/music/fight.ogg b/assets/music/fight.ogg
new file mode 100644
index 0000000..0d54702
--- /dev/null
+++ b/assets/music/fight.ogg
Binary files differ
diff --git a/assets/sounds/badOuch.wav b/assets/sounds/badOuch.wav
new file mode 100644
index 0000000..c799f9e
--- /dev/null
+++ b/assets/sounds/badOuch.wav
Binary files 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
</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)
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 <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;
}
};
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<std::string> 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>()->health -= d;
+ auto h = entity->component<Health>();
+ 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 @@
<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>
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 @@
</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" />
@@ -113,7 +113,7 @@
end
hostile = function()
-
+
end
</Wander>
<Aggro/>
@@ -226,8 +226,7 @@
</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
index 0000000..aaf30cd
--- /dev/null
+++ b/xml/fight.xml
@@ -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>