]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Some more anim
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 1 Dec 2016 02:11:32 +0000 (21:11 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 1 Dec 2016 02:11:32 +0000 (21:11 -0500)
include/components.hpp
src/components.cpp
src/world.cpp
xml/entities.xml

index 4f8ef563643be67ef9586304fa5cbaf46f9c0071..d630f83d0c9f223e504a2069c493218617708163 100644 (file)
@@ -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();
        }
 };
 
index eb9fb0e70ad7690c53b1e07d199372b4fa14433e..b74555cabe6c692db21325a29b9168484ea482ab 100644 (file)
@@ -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();
                        }
index 68b8f345aa35d1621f2babf80f669b0a2111316b..4a7e284edf5c251724ca6ab817311c770be1fae5 100644 (file)
@@ -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]);
index 0d2a519ba2a8bbbf0408e28ac456822d5f28798b..b447dc30d0746d16bb2886d8b87a11b87260f3f9 100644 (file)
                        <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 />