#include <common.hpp>
#include <texture.hpp>
#include <events.hpp>
-
#include <atomic>
+#include <tinyxml2.h>
+using namespace tinyxml2;
/**
* @struct Position
using Frame = std::vector<std::pair<SpriteData, vec2>>;
+std::vector<Frame> developFrame(XMLElement*);
+
//TODO
/**
* @struct Sprite
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);*/
}
};
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,
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);
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();
(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;
+}
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") {
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();
<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 />