From 8c80ad1431512979e364e540a239e806851e4ada Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 30 Nov 2016 14:13:31 -0500 Subject: [PATCH] Animation --- assets/NPC.png.bak | Bin 0 -> 473 bytes assets/NPC_Walk.png | Bin 0 -> 487 bytes assets/NPC_Walk0.png | Bin 0 -> 447 bytes assets/NPC_Walk2.png | Bin 0 -> 493 bytes assets/NPC_Walk3.png | Bin 0 -> 487 bytes assets/NPC_Walk4.png | Bin 0 -> 462 bytes assets/NPC_Walk5.png | Bin 0 -> 490 bytes assets/NPC_Walk6.png | Bin 0 -> 476 bytes assets/NPC_Walk7.png | Bin 0 -> 466 bytes assets/NPC_Walk8.png | Bin 0 -> 468 bytes assets/NPC_Walk9.png | Bin 0 -> 468 bytes assets/items/ironSword.png | Bin 0 -> 326 bytes assets/items/ironSwordRusty.png | Bin 0 -> 612 bytes include/components.hpp | 21 ++++++++++++----- src/components.cpp | 40 +++++++++++++++++++++++++++++++- src/world.cpp | 13 ++++++++++- xml/entities.xml | 37 +++++++++++++++++++++++++++-- 17 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 assets/NPC.png.bak create mode 100644 assets/NPC_Walk.png create mode 100644 assets/NPC_Walk0.png create mode 100644 assets/NPC_Walk2.png create mode 100644 assets/NPC_Walk3.png create mode 100644 assets/NPC_Walk4.png create mode 100644 assets/NPC_Walk5.png create mode 100644 assets/NPC_Walk6.png create mode 100644 assets/NPC_Walk7.png create mode 100644 assets/NPC_Walk8.png create mode 100644 assets/NPC_Walk9.png create mode 100644 assets/items/ironSword.png create mode 100644 assets/items/ironSwordRusty.png diff --git a/assets/NPC.png.bak b/assets/NPC.png.bak new file mode 100644 index 0000000000000000000000000000000000000000..fdebfa93189a744d6271fc43268498fc4017276e GIT binary patch literal 473 zcmV;~0Ve*5P)vP%6WFU8GbZ8()Nlj2>E@cM*00BKoL_t(I%jHzNPQx%1 zJs}ZAVT$A>%FNh)1Y22>fvIGn$9c z*pB1C%w4YJdydb!*AL+Tg=MJGKAhD>%JZBrL{X&0t7IyY)Mz&0oRcnKP!|Zp5I2K~ zmZ*}sYET!gjfm&Adu|r#_VGyqi}7Y(A*c(C(+t)A(6Vi%w-Y{?ahgd)maF|is|*0t zKl{RKS!3wiC_e`P0MSwJz=pmJ02q-YM&u~fE-xGq&!xs`GgSb%n_o-0YubOmo@&ob zS+xuRFV!gk@QG`cpSLjw@;LvgvA!L#zPnGf1mmj`tv9x?T+BFVwccR4m|?ZvfOsyq z?J%(NP-vH$?uJP(OH?&Q?@^WSA5#7`nGup{jE7x@WEx8?Sv}v6@%Q-#c~Ej$JD)+$ P00000NkvXXu0mjfT{FSK literal 0 HcmV?d00001 diff --git a/assets/NPC_Walk.png b/assets/NPC_Walk.png new file mode 100644 index 0000000000000000000000000000000000000000..c342ec325625c009b8cb698327bcc5179a6e7b5b GIT binary patch literal 487 zcmVWFU8GbZ8()Nlj2>E@cM*00B!$L_t(I%f(bXPQySD zeH&W@*_AE3h+I>KL(qlBE~tVVVmCPeQi_}cQHIc1)UM1u;0(wTi9&&b0LhwEYrG#@ zd?GQ@YGm!adGp4z!-xpKwI2Rp{|7ePE*N8VGl+<3W8{W4L9)q7Oc|KxIl8K8CTP_h zR0YB?#Cd-V0EnVUVeaWzgQ`#xd5)#m?7KECZtsNPrac*_2&w|3G{b7M70X_2wk*9E zBZ?vbz$ncGAouH+H+{E#*QUYY2Oi4`!-0YFy$=9rRwV0I{_}8P0054?PetR&kqO_m ziI=YJHfIHZtIIRN?`=F4&74_R_QU!Byuq!^_lvj=tj+$q^Ie;ihApoXEdU+EULVh~ z$a5?LK=awOKKvU1d5%RqUSQ^0x?YwtVe-qF&!+p?B<1s~;J*##fMgQmW|<+G#Db(B dZ4!B#>;NF)sky>Umu>(6002ovPDHLkV1mt;#+U#A literal 0 HcmV?d00001 diff --git a/assets/NPC_Walk0.png b/assets/NPC_Walk0.png new file mode 100644 index 0000000000000000000000000000000000000000..087ff256827a4e387b6bdf07060d9a2d28dbf963 GIT binary patch literal 447 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+h!3HE%S(j%5DYhhUcNd2LAh=-f^2tCE&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=fLl(O!Fto%kV!xx+02lL66gHf+|;}hAeVu`xhOTU zBsE2$JhLQ2!QIn0AVn{goq>T-+0(@_#NzbPkiC9~4Fvw(2~n^No*?;&q37i>?hjmR z=1FO;$iJ|#|6q%k`n3&dsr{h+*IECpqHr#4w zFZ{4$`}Oo4m0vCF_Bw3+QY+&*p~YK=QGg*fDRMgN>rENoQaI)xw2@ShbMJ3Z!nl3jM&nx*V4>y7Mf_Rd(yt~4Xz>@f+wXPfT_R@eSt^K9-(rxVNN mrmxn161?8)*Cqc;wU^(E*sgAwn(Jr}3P(>@KbLh*2~7a{@Uo-; literal 0 HcmV?d00001 diff --git a/assets/NPC_Walk2.png b/assets/NPC_Walk2.png new file mode 100644 index 0000000000000000000000000000000000000000..37273cc57af98068fbcaeb752bad0afa76554a8e GIT binary patch literal 493 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+h!3HE%S(j%5DYhhUcNd2LAh=-f^2tCE&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=fLo52(K6Vfs}(3Dn;8;O;+&tGo0?Ywoq%)r;_s<5BttXKz^kMS0IlbB_blswQ-CC05;ESY7_HmfwX)3DkslO zb!oXD#a_SRKXbV`t3-0BaYu(_@hsle&9koUS+ZI8g2;6fZbgNb1Bd^zc5u|BIdfb* zcSb^arpUCNMTrs5KFHi&bF$j=o zaf@dd!;W1xp?}UD3%;x~(>K*#@0)`3o{5!aovV+W`cZzS+%l7QcAUB!LsZ*dt9i+j zpWk3WFU8GbZ8()Nlj2>E@cM*00B!$L_t(I%f(c|O2a@9 zecJ?;;AoS3$5RbK9f;Syh#7tA4Xc9cQV-JF6=0RZiCss-w%nVECwyEMMLmmllkxz$6voT8g%Sgh7eDSNS6v-IK| zoO1wBvdpcX)XUd*bGJj^rReAr&qaw&WTE&t1OQYk;+!kIwg23SEC9es@TGA)J+=}0 zE{W2O-4KUOIH d=q0J|^ag-3ryaS@L6`sl002ovPDHLkV1g2q$oT*O literal 0 HcmV?d00001 diff --git a/assets/NPC_Walk4.png b/assets/NPC_Walk4.png new file mode 100644 index 0000000000000000000000000000000000000000..8de788f4bc930f4694c2fba3134b7daad6b1cac5 GIT binary patch literal 462 zcmV;<0WtoGP)G03B&m zSad^gZEa<4bN~PV002XBWnpw>WFU8GbZ8()Nlj2>E@cM*00A;dL_t(I%jJ}@O2beT zhQBmLC7l9y37s9=hj6P?1}Dj46AFC*p+lcS9BW;ITi5m>y6H1WKmr+rpoMT{;KHXQ}eCKir|kuo|Ym0*wb1%^(N6cKb1XkaM9kGa{vGU07*qoM6N<$ EfWFU8GbZ8()Nlj2>E@cM*00B-(L_t(I%f(bZOT$1I zel960$&`=``2ij4<{xmgQ$WW|ja2#r3LW|@#7SaZid*HjtnPKv-%tX!)InNQkk{$X zUhYz>7JT72j`w-q_nzlI7!l#OVc`$)f8<(Kf-xq|AR=bOlnq-Ym7`q5+LUO@S85)Q z+8`phx$}MJ)vDuBTPqZJj@j+dca7VQmW2WXqaR2}S07*qoM6N<$g7k&TIsgCw literal 0 HcmV?d00001 diff --git a/assets/NPC_Walk6.png b/assets/NPC_Walk6.png new file mode 100644 index 0000000000000000000000000000000000000000..05e65d9fb8f71cd2b5d8b269a916952f120ef7ed GIT binary patch literal 476 zcmV<20VDp2P)WFU8GbZ8()Nlj2>E@cM*00BTrL_t(I%f(c?O2j}E zJ+r&0BvnFE$Pv5Re5`&j8m1XOH9Q9+K?o!v<$ zan%Jc3`26yeVlV=Mv=sCt%pC@{{;`)97-uI21#Yb)CF4(s#`rtZ`DAXzm;>DryvQp zaK5j+oVCo;MxwxT>}rR;Yi;-D>JZnj33m5SQDjLIM-n6vcn$#&00YlqnWrrCRR5DD zc#;dXL*Hez^^Uvh6T_&F>TMGMkey%ZLU9}$yc=^KMtuOlPVmv7v9~=y=(~J)dQq)v zOH}|kJ~}Y=wH?m}XQ^y!`}T1I0MOZXktG_a&0Y9pWQJh#ld&}b9f#eRwaj}qo#-Xs zas~u%R2D8>7ep{t&PplHrjzx&B-Q=1v9BB~0pn4Ev-t(aqr{-}qnD(9r@sK4iLbtv S(Q7XN0000Fdh=fLl(;TqtoC+h3rNY-UJAiF1B#Zfaf$kjuc}T$Gwv zlA5AWo>`Ki;O^-gkfN8$&cMKE=IP=XVsZLt$VR`z1_HHt0t+ghjVNWRr_bHTQ)lY6eQ{`#}m);yGR(uC32DQKw%d~EWEd9BBdY}5srq4PG49_ADsBmSf ze`&O~dLGHZaKqbS0>Z2H$TVbY|GM(DcgSM`CUuB zUG{wkFN1{6?l=wM44=B6TT=KEPgg!Wiiq68Yzy zILfh<<@zQG;k48MKsq9QzGiO@emq}aRe^GY~*;CByvDN|WFU8GbZ8()Nlj2>E@cM*00B5jL_t(I%f(c&PQx$| zeQqK^&Xmd>@&O&wjUVVQux4tcp#DLJeg+dNomhjiWn~W&KT!z~3j#rx$7B;bPAO1{ zldQ=<_Ixb*QX7jv`pUeAEWTbZ?% zT^B@Syqbj&TrTE^c}X@8FV=T&vL@uS3|H%GFdh=fLl(;LbM{SeQ@mblz2|3Ey# z)-)*K{{mgv)LryczyY4Z5m$5Hi^UgXYsSDD_ZBH8beh6-ksOu zoWJw?cJUq6*DY-KJMFxbE8{t#rAviTfFV>R@~Px%o6Y~v7*$Ntv+QJMN)TcXnV4d` zp#M%*gb+JJ!^&GptG4yMf0OcJ%DcDUo;|*yc;)-v;g7B*q61 ze{wK<`0`23%6PhVZsWB>`SUNn<%o=57ROZ8cGps`*yi-nJ9?jU(+)hCd&bTCKC7X` z`ZPtB>D@mQ<0hSbyn6F{AG4N{Wrch9Ia*!rTe3H9(zCh$n4YTbNDNT>n*$15Pgg&e IbxsLQ047bood5s; literal 0 HcmV?d00001 diff --git a/assets/items/ironSword.png b/assets/items/ironSword.png new file mode 100644 index 0000000000000000000000000000000000000000..632ba86ff512fed9b95561b7df4c6cf9852b5d62 GIT binary patch literal 326 zcmeAS@N?(olHy`uVBq!ia0vp^Ahs9>8<6~|#v2Qy*pj^6T^Rm@;DWu&Cj&(|3p^r= z85p>QL70(Y)*K0-AbW|YuPgflZblw04L6Ib2S6d&%#er@=ltB<)VvZPmw~~#C^fMp zHASI3vm`^o-P1Q9MK6^dD89?y2%SoZ)~}+@qWpJ^8NEWQzJ~0Tj`JeLn)~N~d Nj;E`i%Q~loCIAcYcy9mz literal 0 HcmV?d00001 diff --git a/assets/items/ironSwordRusty.png b/assets/items/ironSwordRusty.png new file mode 100644 index 0000000000000000000000000000000000000000..f2067bdb39a9d6f0e42f8123cc88fd36837a88d6 GIT binary patch literal 612 zcmV-q0-ODbP)WFU8GbZ8()Nlj2>E@cM*00GEJL_t(2&sC92Z&NW4 zg}ZRRSupw`q}LXd=t zr9!3-EJ*|q1wRr<<&SY|oI73j1P8)L$)G-(y;dVMdWiZ?a z@f1auqFCcxyNlsL0|)yf?q3;80O+;H@_vZL-#=)b5jO7bF!=lyGw5$Ng{p2I`t7ll z3YX3X4nDo3ETMnBDa>KzB0!~ZbW(A-6^JD;&+Fgv&j4z0wH-J-si-U=ErxsjVOl5A yV02t@trLjK%2=U(c&jOs()c #include #include - #include +#include +using namespace tinyxml2; /** * @struct Position @@ -138,6 +139,8 @@ struct SpriteData { using Frame = std::vector>; +std::vector developFrame(XMLElement*); + //TODO /** * @struct Sprite @@ -214,14 +217,20 @@ struct Animate { std::vector frame; // COMMENT std::vector::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);*/ } }; diff --git a/src/components.cpp b/src/components.cpp index 28358be..38fd7a6 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -72,7 +72,6 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, Render::worldShader.use(); en.each([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()) { + sprite.sprite = entity.component().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 developFrame(XMLElement* xml) +{ + Frame tmpf; + std::vector tmp; + + // this is the xml elements first child. It will only be the 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; +} diff --git a/src/world.cpp b/src/world.cpp index 8ae93bb..68b8f34 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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(wxml->StrAttribute("inside")); } else if (tname == "Solid") { @@ -381,6 +381,17 @@ void WorldSystem::load(const std::string& file) entity.assign(); } else if (tname == "Wander") { entity.assign(); + } else if (tname == "Animation") { + entity.assign(); + auto animx = abcd->FirstChildElement(); + while (animx) { + std::string animType = animx->Name(); + if (animType == "movement") { + entity.component().get()->frame = developFrame(animx); + } + + animx = animx->NextSiblingElement(); + } } abcd = abcd->NextSiblingElement(); diff --git a/xml/entities.xml b/xml/entities.xml index d95cdc7..0d2a519 100644 --- a/xml/entities.xml +++ b/xml/entities.xml @@ -5,8 +5,41 @@ - assets/NPC.png - assets/NPC_Walk.png + + + assets/NPC.png + + + assets/NPC_Walk.png + + + assets/NPC_Walk2.png + + + assets/NPC_Walk3.png + + + assets/NPC_Walk4.png + + + assets/NPC_Walk5.png + + + assets/NPC_Walk6.png + + + assets/NPC_Walk7.png + + + assets/NPC_Walk8.png + + + assets/NPC_Walk9.png + + + assets/NPC_Walk0.png + + -- 2.39.5