aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.cpp8
-rw-r--r--src/components.cpp80
-rw-r--r--src/engine.cpp5
-rw-r--r--src/ui.cpp2
-rw-r--r--src/world.cpp25
5 files changed, 76 insertions, 44 deletions
diff --git a/src/common.cpp b/src/common.cpp
index 706bc3c..6539a05 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -22,6 +22,14 @@ unsigned int millis(void) {
return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
}
+
+vec2 str2coord(std::string s)
+{
+ auto cpos = s.find(',');
+ s[cpos] = '\0';
+ return vec2 (std::stof(s), std::stof(s.substr(cpos + 1)));
+}
+
std::vector<std::string> StringTokenizer(const std::string& str, char delim)
{
std::vector<std::string> tokens;
diff --git a/src/components.cpp b/src/components.cpp
index f95f46f..7322208 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -21,11 +21,11 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
position.x += direction.x * dt;
position.y += direction.y * dt;
- if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
+ /*if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
auto animate = entity.component<Animate>();
entity.component<Sprite>()->sprite =
(direction.x != 0) ? animate->nextFrame() : animate->firstFrame();
- }
+ }*/
if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) {
direction.x = 0;
} else {
@@ -82,34 +82,36 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
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, 1.0,
- 0.0, 1.0,
- 0.0, 0.0};
+ float its = 0;
+ for (auto &S : sprite.sprite) {
+ auto sp = S.first;
+ auto size = sp.size * game::HLINE;
+ vec2 drawOffset(HLINES(S.second.x), HLINES(S.second.y));
+ vec2 loc(pos.x + drawOffset.x, pos.y + drawOffset.y);
- GLfloat tex_coordL[] = {1.0, 0.0,
- 0.0, 0.0,
- 0.0, 1.0,
+ GLfloat tex_coord[] = {sp.offset_tex.x, sp.offset_tex.y,
+ sp.offset_tex.x + sp.size_tex.x, sp.offset_tex.y,
+ sp.offset_tex.x + sp.size_tex.x, sp.offset_tex.y + sp.size_tex.y,
- 0.0, 1.0,
- 1.0, 1.0,
- 1.0, 0.0};
+ sp.offset_tex.x + sp.size_tex.x, sp.offset_tex.y + sp.size_tex.y,
+ sp.offset_tex.x, sp.offset_tex.y + sp.size_tex.y,
+ sp.offset_tex.x, sp.offset_tex.y};
- for (auto &S : sprite.sprite) {
- const auto& size = S.first.tex.getDim() * game::HLINE;
+ if(sprite.faceLeft) {
+ glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(-1.0f,1.0f,1.0f));
+ glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f - size.x - pos.x * 2.0f, 0.0f, 0.0f));
- vec2 loc = vec2(pos.x + S.first.offset.x, pos.y + S.first.offset.y);
+ glm::mat4 mov = scale * translate;
+ glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(mov));
+ }
- GLfloat coords[] = {loc.x, loc.y, visible.z,
- loc.x + size.x, loc.y, visible.z,
- loc.x + size.x, loc.y + size.y, visible.z,
+ GLfloat coords[] = {loc.x, loc.y, visible.z + its,
+ loc.x + size.x, loc.y, visible.z + its,
+ loc.x + size.x, loc.y + size.y, visible.z + its,
- loc.x + size.x, loc.y + size.y, visible.z,
- loc.x, loc.y + size.y, visible.z,
- loc.x, loc.y, visible.z};
+ loc.x + size.x, loc.y + size.y, visible.z + its,
+ loc.x, loc.y + size.y, visible.z + its,
+ loc.x, loc.y, visible.z + its};
// make the entity hit flash red
@@ -119,19 +121,19 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, flashAmt, flashAmt, 1.0);
}*/
- S.first.tex.use();
+ sp.tex.use();
glUniform1i(Render::worldShader.uniform[WU_texture], 0);
Render::worldShader.enable();
glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords);
- if (sprite.faceLeft)
- glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coordL);
- else
- glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord);
+ glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord);
glDrawArrays(GL_TRIANGLES, 0, 6);
+ glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
+
+ its-=.01;
}
});
@@ -263,6 +265,10 @@ std::vector<Frame> developFrame(XMLElement* xml)
Frame tmpf;
std::vector<Frame> tmp;
+ vec2 foffset;
+ vec2 fsize;
+ vec2 fdraw;
+
// this is the xml elements first child. It will only be the <frame> tag
auto framexml = xml->FirstChildElement();
while (framexml) {
@@ -270,12 +276,24 @@ std::vector<Frame> developFrame(XMLElement* xml)
std::string defframe = framexml->Name();
if (defframe == "frame") {
tmpf.clear();
+ tmp.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)));
+ if (sname == "src") {
+ foffset = (sxml->Attribute("offset") != nullptr) ?
+ str2coord(sxml->Attribute("offset")) : vec2(0,0);
+ fdraw = (sxml->Attribute("drawOffset") != nullptr) ?
+ str2coord(sxml->Attribute("drawOffset")) : vec2(0,0);
+
+ if (sxml->Attribute("size") != nullptr) {
+ fsize = str2coord(sxml->Attribute("size"));
+ tmpf.push_back(std::make_pair(SpriteData(sxml->GetText(), foffset, fsize), fdraw));
+ } else {
+ tmpf.push_back(std::make_pair(SpriteData(sxml->GetText(), foffset), fdraw));
+ }
+ }
sxml = sxml->NextSiblingElement();
}
tmp.push_back(tmpf);
diff --git a/src/engine.cpp b/src/engine.cpp
index b42b162..48e384d 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -40,11 +40,14 @@ void Engine::init(void) {
void Engine::render(entityx::TimeDelta dt)
{
systems.update<RenderSystem>(dt);
- systems.update<WindowSystem>(dt);
//systems.update<InventorySystem>(dt); // doesn't do anything...
ui::fadeUpdate();
}
+void Engine::resetRender(entityx::TimeDelta dt)
+{
+ systems.update<WindowSystem>(dt);
+}
void Engine::update(entityx::TimeDelta dt)
{
diff --git a/src/ui.cpp b/src/ui.cpp
index 9f0e014..6383cca 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -683,7 +683,7 @@ namespace ui {
c2.x, c1.y + boxCornerDim2.y, z, 1.0f, 0.5f,
c2.x, c1.y + boxCornerDim2.y, z, 1.0f, 0.5f,
- c2.x - boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.0f, 0.5f,
+ c2.x - boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.5f, 0.5f,
c2.x - boxCornerDim2.x, c1.y, z, 0.5f, 0.0f};
GLfloat box_l[] = {c1.x, c1.y + boxCornerDim2.y, z, 0.0f, 0.0f,
diff --git a/src/world.cpp b/src/world.cpp
index d0727e2..6b18542 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -182,11 +182,6 @@ bool WorldSystem::save(void)
void WorldSystem::load(const std::string& file)
{
auto& render = *game::engine.getSystem<RenderSystem>();
- auto str2coord = [](std::string s) -> vec2 {
- auto cpos = s.find(',');
- s[cpos] = '\0';
- return vec2 (std::stof(s), std::stof(s.substr(cpos + 1)));
- };
entityx::Entity entity;
@@ -331,10 +326,10 @@ void WorldSystem::load(const std::string& file)
entity.assign<Visible>(abcd->FloatAttribute("value"));
} else if (tname == "Sprite") {
auto sprite = entity.assign<Sprite>();
- auto tex = abcd->Attribute("image");
- sprite->addSpriteSegment(SpriteData(tex,
- vec2(0, 0)),
- vec2(0, 0));
+ auto sprx = abcd;
+ auto frames = developFrame(sprx);
+ if (frames.size())
+ sprite->sprite = frames.at(0);
} else if (tname == "Portal") {
entity.assign<Portal>(wxml->StrAttribute("inside"));
} else if (tname == "Solid") {
@@ -381,12 +376,20 @@ void WorldSystem::load(const std::string& file)
} else if (tname == "Wander") {
entity.assign<Wander>();
} else if (tname == "Animation") {
- entity.assign<Animate>();
+ auto entan = entity.assign<Animate>();
auto animx = abcd->FirstChildElement();
+ uint idtc = 0;
while (animx) {
std::string animType = animx->Name();
if (animType == "movement") {
- entity.component<Animate>().get()->frame = developFrame(animx);
+ auto frames = developFrame(animx);
+ if (animx->UnsignedAttribute("changeID") != XML_NO_ERROR)
+ idtc = 0;
+ else
+ idtc = animx->UnsignedAttribute("changeID");
+ for (uint i = 0; i < frames.size(); i++) {
+ entan->frame.push_back(std::make_pair(idtc, frames[i]));
+ }
}
animx = animx->NextSiblingElement();