]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
When entities stop, their legs stop
authorAndy <drumsetmonkey@gmail.com>
Thu, 19 Jan 2017 14:27:20 +0000 (09:27 -0500)
committerAndy <drumsetmonkey@gmail.com>
Thu, 19 Jan 2017 14:27:20 +0000 (09:27 -0500)
include/components.hpp
src/components.cpp

index f8eeaf168959c958270dc263e202e80fa8815758..e0147b0e3898f67100e7d9b7b30ea400c59023ea 100644 (file)
@@ -255,6 +255,22 @@ struct Limb {
                frame.push_back(fr);
        }
 
+       void firstFrame(Frame& duckmyass) {
+               // loop through the spritedata of the sprite we wanna change
+               for (auto &d : duckmyass) {
+                       // if the sprite data is the same limb as this limb
+                       if (d.first.limb == limbID) {
+                               // rotate through (for safety) the first frame to set the limb
+                               for (auto &fa : frame.at(0)) {
+                                       if (fa.first.limb == limbID) {
+                                               d.first = fa.first;
+                                               d.second = fa.second;
+                                       }
+                               }
+                       }
+               }
+       }
+
        void nextFrame(Frame& duckmyass, float dt) {
                updateCurrent -= dt;
                if (updateCurrent <= 0) {
@@ -306,8 +322,13 @@ struct Animate {
 
        // COMMENT
 
-       void firstFrame(Frame &sprite) {
-               (void)sprite;
+       void firstFrame(uint updateType, Frame &sprite) {
+               uint upid = updateType; //^see todo
+               for (auto &l : limb) {
+                       if (l.updateType == upid) {
+                               l.firstFrame(sprite);
+                       }
+               }
        }
         //TODO make updateType an enum
        void updateAnimation(uint updateType, Frame& sprite, float dt) {
index b06bf84f14bc2f37f938859b42dd671d629076d0..2bd93fcef4dbabb4aff8ab41a30576da00297e10 100644 (file)
@@ -26,9 +26,12 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
                        auto animate = entity.component<Animate>();
                        auto sprite =  entity.component<Sprite>();
-                       
-                       animate->updateAnimation(1, sprite->sprite, dt);
-               }
+               
+                       if (direction.x)        
+                               animate->updateAnimation(1, sprite->sprite, dt);
+                       else
+                               animate->firstFrame(1, sprite->sprite);
+                       }
                if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) {
                        direction.x = 0;
                } else {