aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--assets/NPC.png.bakbin0 -> 473 bytes
-rw-r--r--assets/NPC_Walk.pngbin0 -> 487 bytes
-rw-r--r--assets/NPC_Walk0.pngbin0 -> 447 bytes
-rw-r--r--assets/NPC_Walk2.pngbin0 -> 493 bytes
-rw-r--r--assets/NPC_Walk3.pngbin0 -> 487 bytes
-rw-r--r--assets/NPC_Walk4.pngbin0 -> 462 bytes
-rw-r--r--assets/NPC_Walk5.pngbin0 -> 490 bytes
-rw-r--r--assets/NPC_Walk6.pngbin0 -> 476 bytes
-rw-r--r--assets/NPC_Walk7.pngbin0 -> 466 bytes
-rw-r--r--assets/NPC_Walk8.pngbin0 -> 468 bytes
-rw-r--r--assets/NPC_Walk9.pngbin0 -> 468 bytes
-rw-r--r--assets/items/ironSword.pngbin0 -> 326 bytes
-rw-r--r--assets/items/ironSwordRusty.pngbin0 -> 612 bytes
-rw-r--r--include/components.hpp21
-rw-r--r--src/components.cpp40
-rw-r--r--src/world.cpp13
-rw-r--r--xml/entities.xml37
17 files changed, 101 insertions, 10 deletions
diff --git a/assets/NPC.png.bak b/assets/NPC.png.bak
new file mode 100644
index 0000000..fdebfa9
--- /dev/null
+++ b/assets/NPC.png.bak
Binary files differ
diff --git a/assets/NPC_Walk.png b/assets/NPC_Walk.png
new file mode 100644
index 0000000..c342ec3
--- /dev/null
+++ b/assets/NPC_Walk.png
Binary files differ
diff --git a/assets/NPC_Walk0.png b/assets/NPC_Walk0.png
new file mode 100644
index 0000000..087ff25
--- /dev/null
+++ b/assets/NPC_Walk0.png
Binary files differ
diff --git a/assets/NPC_Walk2.png b/assets/NPC_Walk2.png
new file mode 100644
index 0000000..37273cc
--- /dev/null
+++ b/assets/NPC_Walk2.png
Binary files differ
diff --git a/assets/NPC_Walk3.png b/assets/NPC_Walk3.png
new file mode 100644
index 0000000..79c8401
--- /dev/null
+++ b/assets/NPC_Walk3.png
Binary files differ
diff --git a/assets/NPC_Walk4.png b/assets/NPC_Walk4.png
new file mode 100644
index 0000000..8de788f
--- /dev/null
+++ b/assets/NPC_Walk4.png
Binary files differ
diff --git a/assets/NPC_Walk5.png b/assets/NPC_Walk5.png
new file mode 100644
index 0000000..a2fc130
--- /dev/null
+++ b/assets/NPC_Walk5.png
Binary files differ
diff --git a/assets/NPC_Walk6.png b/assets/NPC_Walk6.png
new file mode 100644
index 0000000..05e65d9
--- /dev/null
+++ b/assets/NPC_Walk6.png
Binary files differ
diff --git a/assets/NPC_Walk7.png b/assets/NPC_Walk7.png
new file mode 100644
index 0000000..20baa62
--- /dev/null
+++ b/assets/NPC_Walk7.png
Binary files differ
diff --git a/assets/NPC_Walk8.png b/assets/NPC_Walk8.png
new file mode 100644
index 0000000..42e4750
--- /dev/null
+++ b/assets/NPC_Walk8.png
Binary files differ
diff --git a/assets/NPC_Walk9.png b/assets/NPC_Walk9.png
new file mode 100644
index 0000000..01a1bf7
--- /dev/null
+++ b/assets/NPC_Walk9.png
Binary files differ
diff --git a/assets/items/ironSword.png b/assets/items/ironSword.png
new file mode 100644
index 0000000..632ba86
--- /dev/null
+++ b/assets/items/ironSword.png
Binary files differ
diff --git a/assets/items/ironSwordRusty.png b/assets/items/ironSwordRusty.png
new file mode 100644
index 0000000..f2067bd
--- /dev/null
+++ b/assets/items/ironSwordRusty.png
Binary files differ
diff --git a/include/components.hpp b/include/components.hpp
index 551df53..4f8ef56 100644
--- a/include/components.hpp
+++ b/include/components.hpp
@@ -13,8 +13,9 @@
#include <common.hpp>
#include <texture.hpp>
#include <events.hpp>
-
#include <atomic>
+#include <tinyxml2.h>
+using namespace tinyxml2;
/**
* @struct Position
@@ -138,6 +139,8 @@ struct SpriteData {
using Frame = std::vector<std::pair<SpriteData, vec2>>;
+std::vector<Frame> developFrame(XMLElement*);
+
//TODO
/**
* @struct Sprite
@@ -214,14 +217,20 @@ struct Animate {
std::vector<Frame> frame;
// COMMENT
std::vector<Frame>::iterator currentFrame;
-
+
+ Animate(){
+ currentFrame = std::begin(frame);
+ }
+
// COMMENT
Frame nextFrame() {
- if (currentFrame != std::end(frame))
- currentFrame++;
- else
+ std::rotate(frame.begin(), frame.begin()+1, frame.end());
+ return frame[0];
+ /*if (currentFrame < std::end(frame))
+ return (*currentFrame++);
+ else
currentFrame = std::begin(frame);
- return *currentFrame;
+ return (*currentFrame);*/
}
};
diff --git a/src/components.cpp b/src/components.cpp
index 28358be..38fd7a6 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -72,7 +72,6 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
Render::worldShader.use();
en.each<Visible, Sprite, Position>([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
- (void)entity;
// Verticies and shit
GLfloat tex_coord[] = {0.0, 0.0,
1.0, 0.0,
@@ -90,6 +89,10 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
1.0, 1.0,
1.0, 0.0};
+ if (entity.has_component<Animate>()) {
+ sprite.sprite = entity.component<Animate>().get()->nextFrame();
+ }
+
for (auto &S : sprite.sprite) {
float width = HLINES(S.first.size.x);
float height = HLINES(S.first.size.y);
@@ -111,7 +114,9 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
float flashAmt = 1-(hitDuration/maxHitDuration);
glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, flashAmt, flashAmt, 1.0);
}*/
+
glBindTexture(GL_TEXTURE_2D, S.first.pic);
+
glUniform1i(Render::worldShader.uniform[WU_texture], 0);
Render::worldShader.enable();
@@ -207,3 +212,36 @@ void DialogSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
(void)ev;
(void)dt;
}
+
+std::vector<Frame> developFrame(XMLElement* xml)
+{
+ Frame tmpf;
+ std::vector<Frame> tmp;
+
+ // this is the xml elements first child. It will only be the <frame> tag
+ auto framexml = xml->FirstChildElement();
+ while (framexml) {
+ // this will always be frame. but if it isn't we don't wanna crash the game
+ std::string defframe = framexml->Name();
+ if (defframe == "frame") {
+ tmpf.clear();
+ // the xml element to parse each src of the frames
+ auto sxml = framexml->FirstChildElement();
+ while (sxml) {
+ std::string sname = sxml->Name();
+ if (sname == "src") {
+ tmpf.push_back(std::make_pair(SpriteData(sxml->GetText(), vec2(0,0)), vec2(0,0)));
+ std::cout << tmpf.back().first.pic << std::endl;
+ }
+ sxml = sxml->NextSiblingElement();
+ }
+ tmp.push_back(tmpf);
+ }
+ // if it's not a frame we don't care
+
+ // parse next frame
+ framexml = framexml->NextSiblingElement();
+ }
+
+ return tmp;
+}
diff --git a/src/world.cpp b/src/world.cpp
index 8ae93bb..68b8f34 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -335,7 +335,7 @@ void WorldSystem::load(const std::string& file)
auto tex = abcd->Attribute("image");
sprite->addSpriteSegment(SpriteData(tex,
vec2(0, 0)),
- vec2(0, 0));
+ vec2(0, 0));
} else if (tname == "Portal") {
entity.assign<Portal>(wxml->StrAttribute("inside"));
} else if (tname == "Solid") {
@@ -381,6 +381,17 @@ void WorldSystem::load(const std::string& file)
entity.assign<Grounded>();
} else if (tname == "Wander") {
entity.assign<Wander>();
+ } else if (tname == "Animation") {
+ entity.assign<Animate>();
+ auto animx = abcd->FirstChildElement();
+ while (animx) {
+ std::string animType = animx->Name();
+ if (animType == "movement") {
+ entity.component<Animate>().get()->frame = developFrame(animx);
+ }
+
+ animx = animx->NextSiblingElement();
+ }
}
abcd = abcd->NextSiblingElement();
diff --git a/xml/entities.xml b/xml/entities.xml
index d95cdc7..0d2a519 100644
--- a/xml/entities.xml
+++ b/xml/entities.xml
@@ -5,8 +5,41 @@
<Visible value="0.2" />
<Sprite image="assets/NPC.png" />
<Animation>
- <frame>assets/NPC.png</frame>
- <frame>assets/NPC_Walk.png</frame>
+ <movement>
+ <frame>
+ <src>assets/NPC.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk2.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk3.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk4.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk5.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk6.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk7.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk8.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk9.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk0.png</src>
+ </frame>
+ </movement>
</Animation>
<Direction />
<Solid />