diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-11-30 21:11:32 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-11-30 21:11:32 -0500 |
commit | 44a42be2087b0d6e4b732596029d8f41d7ca6b40 (patch) | |
tree | 3c5ee20a47fcc55173b7026ebc8139d02810494d | |
parent | 1024fe8305e5b0a7bb1f660a1cee077172d84534 (diff) |
Some more anim
-rw-r--r-- | include/components.hpp | 21 | ||||
-rw-r--r-- | src/components.cpp | 15 | ||||
-rw-r--r-- | src/world.cpp | 29 | ||||
-rw-r--r-- | xml/entities.xml | 30 |
4 files changed, 68 insertions, 27 deletions
diff --git a/include/components.hpp b/include/components.hpp index 4f8ef56..d630f83 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -216,21 +216,24 @@ struct Animate { // COMMENT std::vector<Frame> frame; // COMMENT - std::vector<Frame>::iterator currentFrame; + uint index; Animate(){ - currentFrame = std::begin(frame); + index = 0; } // COMMENT Frame nextFrame() { - 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);*/ + if (index < frame.size() - 1) { + index++; + } else { + index = 0; + } + return frame.at(index); + } + + Frame firstFrame() { + return frame.front(); } }; diff --git a/src/components.cpp b/src/components.cpp index eb9fb0e..b74555c 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -18,7 +18,14 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e en.each<Position, Direction>([dt](entityx::Entity entity, Position &position, Direction &direction) { position.x += direction.x * dt; position.y += direction.y * dt; - + + if (entity.has_component<Animate>() && entity.has_component<Sprite>()) { + if (direction.x) { + entity.component<Sprite>().get()->sprite = entity.component<Animate>().get()->nextFrame(); + } else { + entity.component<Sprite>().get()->sprite = entity.component<Animate>().get()->firstFrame(); + } + } if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) { direction.x = 0; } else { @@ -73,6 +80,7 @@ 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, @@ -89,10 +97,6 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, 0.0, 1.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); @@ -265,7 +269,6 @@ std::vector<Frame> developFrame(XMLElement* xml) 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(); } diff --git a/src/world.cpp b/src/world.cpp index 68b8f34..4a7e284 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1043,19 +1043,22 @@ void WorldSystem::render(void) static const auto blackTex = Texture::genColor(Color(0, 0, 0)); static const float sheight = static_cast<float>(SCREEN_HEIGHT); + if (offset.x + world.startX > s) { glBindTexture(GL_TEXTURE_2D, blackTex); glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.0f); + auto off = offset.y - static_cast<float>(SCREEN_HEIGHT) / 2.0f; + GLfloat blackBarLeft[] = { - s, 0.0f, -3.5f, 0.0f, 0.0f, - world.startX, 0.0f, -3.5f, 1.0f, 0.0f, - world.startX, sheight, -3.5f, 1.0f, 1.0f, + s, 0.0f + off, -3.5f, 0.0f, 0.0f, + world.startX, 0.0f + off, -3.5f, 1.0f, 0.0f, + world.startX, sheight + off, -3.5f, 1.0f, 1.0f, - world.startX, sheight, -3.5f, 1.0f, 1.0f, - s, sheight, -3.5f, 0.0f, 1.0f, - s, 0.0f, -3.5f, 0.0f, 0.0f + world.startX, sheight + off, -3.5f, 1.0f, 1.0f, + s, sheight + off, -3.5f, 0.0f, 1.0f, + s, 0.0f + off, -3.5f, 0.0f, 0.0f }; glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, &blackBarLeft[0]); @@ -1066,15 +1069,17 @@ void WorldSystem::render(void) if (offset.x - world.startX < e) { glBindTexture(GL_TEXTURE_2D, blackTex); glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.0f); + + auto off = offset.y - static_cast<float>(SCREEN_HEIGHT) / 2.0f; GLfloat blackBarRight[] = { - -(world.startX), 0.0f, -3.5f, 0.0f, 0.0f, - e, 0.0f, -3.5f, 1.0f, 0.0f, - e, sheight, -3.5f, 1.0f, 1.0f, + -(world.startX), 0.0f + off, -3.5f, 0.0f, 0.0f, + e, 0.0f + off, -3.5f, 1.0f, 0.0f, + e, sheight + off, -3.5f, 1.0f, 1.0f, - e, sheight, -3.5f, 1.0f, 1.0f, - -(world.startX), sheight, -3.5f, 0.0f, 1.0f, - -(world.startX), 0.0f, -3.5f, 0.0f, 0.0f + e, sheight + off, -3.5f, 1.0f, 1.0f, + -(world.startX), sheight + off, -3.5f, 0.0f, 1.0f, + -(world.startX), 0.0f + off, -3.5f, 0.0f, 0.0f }; glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, &blackBarRight[0]); diff --git a/xml/entities.xml b/xml/entities.xml index 0d2a519..b447dc3 100644 --- a/xml/entities.xml +++ b/xml/entities.xml @@ -39,6 +39,36 @@ <frame> <src>assets/NPC_Walk0.png</src> </frame> + <frame> + <src>assets/NPC_Walk9.png</src> + </frame> + <frame> + <src>assets/NPC_Walk8.png</src> + </frame> + <frame> + <src>assets/NPC_Walk7.png</src> + </frame> + <frame> + <src>assets/NPC_Walk6.png</src> + </frame> + <frame> + <src>assets/NPC_Walk5.png</src> + </frame> + <frame> + <src>assets/NPC_Walk4.png</src> + </frame> + <frame> + <src>assets/NPC_Walk3.png</src> + </frame> + <frame> + <src>assets/NPC_Walk2.png</src> + </frame> + <frame> + <src>assets/NPC_Walk.png</src> + </frame> + <frame> + <src>assets/NPC.png</src> + </frame> </movement> </Animation> <Direction /> |