diff options
author | Andy <drumsetmonkey@gmail.com> | 2017-01-20 10:37:18 -0500 |
---|---|---|
committer | Andy <drumsetmonkey@gmail.com> | 2017-01-20 10:37:18 -0500 |
commit | 1894e311bdeb098c3bef9bd342e0eaf78d197a9b (patch) | |
tree | 4f6005cc8f7aafa8f480e2c8f70d2ca80a552e8f /src | |
parent | 36ed75a7749b81fab69f66b9ef8bbf0d18489f73 (diff) |
Walking player
Diffstat (limited to 'src')
-rw-r--r-- | src/player.cpp | 102 |
1 files changed, 100 insertions, 2 deletions
diff --git a/src/player.cpp b/src/player.cpp index c0710cc..78c0b8e 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -9,11 +9,64 @@ static const char *spriteXML = "<Sprite> \ <frame> \ - <src limb='0' offset='0,0' size='15,23' drawOffset='0,9'>assets/player/player.png</src> \ - <src limb='1' offset='15,0' size='12,11' drawOffset='2,0'>assets/player/player.png</src>\ + <src limb='0' offset='0,0' size='15,16' drawOffset='0,9'>assets/player/player.png</src> \ + <src limb='1' offset='0,16' size='13,12' drawOffset='0,20'>assets/player/player.png</src>\ + <src limb='2' offset='15,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + <src limb='3' offset='15,14' size='15,13' drawOffset='0,9'>assets/player/player.png</src>\ </frame> \ </Sprite>"; +static const char *animationXML = + "<Animation>\ + <movement>\ + <limb update='60.0' id='2'>\ + <frame>\ + <src offset='15,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='29,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='43,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='57,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='71,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='85,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='99,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='113,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='127,0' size='14,11' drawOffset='1,0'>assets/player/player.png</src>\ + </frame>\ + </limb>\ + </movement>\ + <movement>\ + <limb update='250.0' id='3'>\ + <frame>\ + <src offset='15,14' size='15,13' drawOffset='0,9'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='32,14' size='14,13' drawOffset='0,9'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='50,14' size='14,13' drawOffset='0,9'>assets/player/player.png</src>\ + </frame>\ + <frame>\ + <src offset='68,14' size='17,13' drawOffset='-1,9'>assets/player/player.png</src>\ + </frame>\ + </limb>\ + </movement>\ + </Animation>"; + void PlayerSystem::create(void) { player = game::entities.create(); @@ -32,6 +85,51 @@ void PlayerSystem::create(void) vec2 dim = player.component<Sprite>().get()->getSpriteSize(); float cdat[2] = {dim.x, dim.y}; player.assign<Solid>(cdat[0], cdat[1]); + + // handle player animation + xmld.Parse(animationXML); + auto entan = player.assign<Animate>(); + auto animx = xmld.FirstChildElement()->FirstChildElement(); + + uint limbid = 0; + float limbupdate = 0; + uint limbupdatetype = 0; + + while (animx) { + std::string animType = animx->Name(); + std::cout << animx->Name() << std::endl; + if (animType == "movement") { + limbupdatetype = 1; + auto limbx = animx->FirstChildElement(); + while (limbx) { + std::string limbHopefully = limbx->Name(); + if (limbHopefully == "limb") { + auto frames = developFrame(limbx); + + entan->limb.push_back(Limb()); + entan->limb.back().updateType = limbupdatetype; + + if (limbx->QueryUnsignedAttribute("id", &limbid) == XML_NO_ERROR) { + entan->limb.back().limbID = limbid; + } + if (limbx->QueryFloatAttribute("update", &limbupdate) == XML_NO_ERROR) { + entan->limb.back().updateRate = limbupdate; + } + + // place our newly developed frames in the entities animation stack + for (auto &f : frames) { + entan->limb.back().addFrame(f); + for (auto &fr : entan->limb.back().frame) { + for (auto &sd : fr) + sd.first.limb = limbid; + } + } + } + limbx = limbx->NextSiblingElement(); + } + } + animx = animx->NextSiblingElement(); + } } void PlayerSystem::configure(entityx::EventManager &ev) |