]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Animation
authorAndy <drumsetmonkey@gmail.com>
Wed, 30 Nov 2016 19:13:31 +0000 (14:13 -0500)
committerAndy <drumsetmonkey@gmail.com>
Wed, 30 Nov 2016 19:13:31 +0000 (14:13 -0500)
17 files changed:
assets/NPC.png.bak [new file with mode: 0644]
assets/NPC_Walk.png [new file with mode: 0644]
assets/NPC_Walk0.png [new file with mode: 0644]
assets/NPC_Walk2.png [new file with mode: 0644]
assets/NPC_Walk3.png [new file with mode: 0644]
assets/NPC_Walk4.png [new file with mode: 0644]
assets/NPC_Walk5.png [new file with mode: 0644]
assets/NPC_Walk6.png [new file with mode: 0644]
assets/NPC_Walk7.png [new file with mode: 0644]
assets/NPC_Walk8.png [new file with mode: 0644]
assets/NPC_Walk9.png [new file with mode: 0644]
assets/items/ironSword.png [new file with mode: 0644]
assets/items/ironSwordRusty.png [new file with mode: 0644]
include/components.hpp
src/components.cpp
src/world.cpp
xml/entities.xml

diff --git a/assets/NPC.png.bak b/assets/NPC.png.bak
new file mode 100644 (file)
index 0000000..fdebfa9
Binary files /dev/null and b/assets/NPC.png.bak differ
diff --git a/assets/NPC_Walk.png b/assets/NPC_Walk.png
new file mode 100644 (file)
index 0000000..c342ec3
Binary files /dev/null and b/assets/NPC_Walk.png differ
diff --git a/assets/NPC_Walk0.png b/assets/NPC_Walk0.png
new file mode 100644 (file)
index 0000000..087ff25
Binary files /dev/null and b/assets/NPC_Walk0.png differ
diff --git a/assets/NPC_Walk2.png b/assets/NPC_Walk2.png
new file mode 100644 (file)
index 0000000..37273cc
Binary files /dev/null and b/assets/NPC_Walk2.png differ
diff --git a/assets/NPC_Walk3.png b/assets/NPC_Walk3.png
new file mode 100644 (file)
index 0000000..79c8401
Binary files /dev/null and b/assets/NPC_Walk3.png differ
diff --git a/assets/NPC_Walk4.png b/assets/NPC_Walk4.png
new file mode 100644 (file)
index 0000000..8de788f
Binary files /dev/null and b/assets/NPC_Walk4.png differ
diff --git a/assets/NPC_Walk5.png b/assets/NPC_Walk5.png
new file mode 100644 (file)
index 0000000..a2fc130
Binary files /dev/null and b/assets/NPC_Walk5.png differ
diff --git a/assets/NPC_Walk6.png b/assets/NPC_Walk6.png
new file mode 100644 (file)
index 0000000..05e65d9
Binary files /dev/null and b/assets/NPC_Walk6.png differ
diff --git a/assets/NPC_Walk7.png b/assets/NPC_Walk7.png
new file mode 100644 (file)
index 0000000..20baa62
Binary files /dev/null and b/assets/NPC_Walk7.png differ
diff --git a/assets/NPC_Walk8.png b/assets/NPC_Walk8.png
new file mode 100644 (file)
index 0000000..42e4750
Binary files /dev/null and b/assets/NPC_Walk8.png differ
diff --git a/assets/NPC_Walk9.png b/assets/NPC_Walk9.png
new file mode 100644 (file)
index 0000000..01a1bf7
Binary files /dev/null and b/assets/NPC_Walk9.png differ
diff --git a/assets/items/ironSword.png b/assets/items/ironSword.png
new file mode 100644 (file)
index 0000000..632ba86
Binary files /dev/null and b/assets/items/ironSword.png differ
diff --git a/assets/items/ironSwordRusty.png b/assets/items/ironSwordRusty.png
new file mode 100644 (file)
index 0000000..f2067bd
Binary files /dev/null and b/assets/items/ironSwordRusty.png differ
index 551df53c153f83f33e2f579721d21ef6a14c0f86..4f8ef563643be67ef9586304fa5cbaf46f9c0071 100644 (file)
@@ -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);*/
        }
 };
 
index 28358bede5b924e578a8758bc2839b1e66e70ca0..38fd7a6ab412a61a021c111d5a3a04b14b147950 100644 (file)
@@ -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;
+}
index 8ae93bbe01ba6762a113e02c985e19182509f712..68b8f345aa35d1621f2babf80f669b0a2111316b 100644 (file)
@@ -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();
index d95cdc768abe9f6ce1a6304b717ba6ba3f0dcc49..0d2a519ba2a8bbbf0408e28ac456822d5f28798b 100644 (file)
@@ -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 />