From 691411cdb214178f2d10ab589943993039fe080e Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 22 Dec 2016 10:50:27 -0500 Subject: [PATCH] Sprites flip and shit are good --- assets/NPC.png | Bin 473 -> 555 bytes assets/goodmouse.png | Bin 0 -> 6652 bytes assets/mouse.png | Bin 540 -> 1100 bytes include/common.hpp | 8 ++++ include/components.hpp | 31 ++++++++++++--- include/engine.hpp | 1 + main.cpp | 8 ++-- src/common.cpp | 8 ++++ src/components.cpp | 80 ++++++++++++++++++++++++--------------- src/engine.cpp | 5 ++- src/ui.cpp | 2 +- src/world.cpp | 25 +++++++------ xml/entities.xml | 83 ++++++++++------------------------------- 13 files changed, 135 insertions(+), 116 deletions(-) create mode 100644 assets/goodmouse.png diff --git a/assets/NPC.png b/assets/NPC.png index 801ceb0649cc0851b4a5ad6f5e72be6ddb85bc5b..7c46dce49a8c108ed827d89202faebc6815b373f 100644 GIT binary patch delta 502 zcmV#-M z)H-JMFZA!onbpKtp9^Lcv!UOT>m4ODZh<3yoH`hJ>u4FhRj=#zJP; z8D?LcWHbA?=bn4d-WdV~g^bA%fVc54;r9uZc(`jK1dJ!xh^nXq;l$6Gft{oqi6lxd zWK5P#r+?Vx!8XgLQ!G{mg^al#k@x)YI>*`mX55yShCRK1OTQsj=~x3nN-Qjn_>l&K zfp}4=RJ8FbnR!Vn7D>p8VJhwaSm(ng|rw zT7KhwO9x=@rlBQ70<|r+$jUnHmbmyc0OoaDQua)b@BUtyFm-2j+O2rUkRL|lFKLZT s<|l+ky@uOfAB}oVYKep#KY_FH2h5P4XJo03IRF3v07*qoM6N<$f+hvrnE(I) delta 419 zcmV;U0bKs81la?S7ep8c1^@s6B?YHx00006VoOIv0RI600RN!9r;`8x010qNS#tmY z3ljhU3ljkVnw%H_000McNliru;0qT52Q&@;SqYI_EPp*oL_t(I%jHzNPQx%1Js}ZA zVT$A>%FNh)1Y22>fvIGn$9c*pB1C z%w4YJdydb!*AL+Tg=MJGKAhD>%JZBrL{X&0t7IyY)Mz&0oRcnKP!|Zp5I2K~mZ*}s zYET!gjem&ewtH?C>GttS0*moxUm>UqjMEI&{?M{*rMDA4m~om(M3$@lL8}Y^)Ia;e zYguFH+bBN=007ZZ@4$w>4FDLCBSz#X)h;g_5YMH?X){#-xSL-~xog^gzn*H(Oj)%I z058=k0Pu-xm7ljU2l6=osj%}>wy<2xIB2!rV7ZuKwcdbuF1PJ4 zu<}r7mzwT|NiR!OHAU}HmG2)?{xz8ql4*>GU4~>DOD$PF-;eS4`38AVa#=f{LCydG N002ovPDHLkV1gY%x2gaD diff --git a/assets/goodmouse.png b/assets/goodmouse.png new file mode 100644 index 0000000000000000000000000000000000000000..72c44096b67f336ba733a2fd3f0f5a16cc98ae04 GIT binary patch literal 6652 zcmV77Alq5*jTd&E7M;{QCEM%f0uU z{PDVnk@2FDgn{H%y?XV%-Szvud)~R{e9!mXp8)6i%wqrydGbT}D>wwOXYjNB$_>Z= z=ObJU%s#&}h{#|0xBgiT@Jx=+Wz36>Xl8!~|AobXXVL>c(`S9#k9^tEuv{IxyfE87 zxwSpHd@*gG+~VVZ@Nr)L`rB}MfnEH6j@rYa58j7sMOfQ*rH!ug~_kPami6 ze)u|hyuS6!iF0ArY%h;iCO@)zYf zoS)j9Z-*RhYwJAoZcFxEz4v*yyzu5%@4I?0x4iIX$|5lDwzwGorOX0PC2EW3IuTt$ zv&@?rbvI>Y&t%WR>koY2+u!uBKK#b-{^nEHUVVT!zVLf+0^SMUImUy42#7ckAt$Aa znc*Nj0VmbJTxoE3>|Y)aWZ<8F_=VTJ_1dqvVcbq4UOe0NoTahK!oJCiZ@TIF|MZhT z_|yM-->^LO%4h8>FTY}8Wo5Zs84heRnk;m#S~_*&*!m+MIr8Y47vFqM^N}Nu@+T)Y zshf`P_?p}J$dN}G4@>GcqIzk8^K(&Q`D}0Z$#}rQ$zby08xGuh(@PG0=k&7bt0&hk zSJj?@pEfmF6Z==L;L3g1lQt8NfB3$1-+SL5mn+ZYs^u`)J9O5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mV+%0^|LOP)dB{X(~-qAp}!XQ=g8g`i`sEh_X8>m&>9k z((m`R+il%$*XHJ?G)?t-J?rc1R#sNvEiR!`z>Q4K^ALjl{e7^zyK8lI6;vt}tyatY z{5(9xGS-T?fGfGCQmF*Cx3`UrjftX2wOY-WA7UepH4Ti&^D2hO@*Hf?8 zbLeqi8y}-6G8ha*_=7g?#Bn_8%FfPCK75f~>npy^&d&CS!{KOO36JmwA%qapG!2cfl7y*Ss;n3UN%;ANFg&cf|`#4*x z)efC@G%A_L?`7a?+(LbBZcdUU$3pq}r!o)!%dD6?=~o=be?tiJJQ#U<_cHUJ!3liM eep%}{D3AZf@2PGn1iE4X0000 StringTokenizer(const std::string& str, char delim); +/** + * Seperates a string like, "23,12" to a vec2. + * + * @param s the string to parse + * @return the vec2 of the values passed in the string + */ +vec2 str2coord(std::string s); + /** * A function to draw a colored box for OpenGL. * To use it, the lower left hand and upper right hand coords are given. diff --git a/include/components.hpp b/include/components.hpp index d630f83..2a8680d 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -130,11 +130,28 @@ struct SpriteData { offset(offset) { pic = Texture::loadTexture(path); size = Texture::imageDim(path); - } + size_tex = vec2(1.0, 1.0); + + offset_tex.x = offset.x/size.x; + offset_tex.y = offset.y/size.y; + } + + SpriteData(std::string path, vec2 offset, vec2 size): + offset(offset), size(size) { + pic = Texture::loadTexture(path); + vec2 tmpsize = Texture::imageDim(path); + + size_tex.x = size.x/tmpsize.x; + size_tex.y = size.y/tmpsize.y; + offset_tex.x = offset.x/tmpsize.x; + offset_tex.y = offset.y/tmpsize.y; + } GLuint pic; vec2 offset; + vec2 offset_tex; vec2 size; + vec2 size_tex; }; using Frame = std::vector>; @@ -214,7 +231,7 @@ struct Sprite { //TODO struct Animate { // COMMENT - std::vector frame; + std::vector> frame; // COMMENT uint index; @@ -223,17 +240,19 @@ struct Animate { } // COMMENT - Frame nextFrame() { + void nextFrame(Frame sprite) { if (index < frame.size() - 1) { index++; } else { index = 0; } - return frame.at(index); + auto fa = frame.at(index); + if (sprite.size() > fa.first-1) + sprite.at(fa.first) = fa.second.at(fa.first); } - Frame firstFrame() { - return frame.front(); + void firstFrame(Frame sprite) { + sprite = frame.at(0).second; } }; diff --git a/include/engine.hpp b/include/engine.hpp index c842b59..1c5f510 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -20,6 +20,7 @@ public: void init(void); void render(entityx::TimeDelta dt); + void resetRender(entityx::TimeDelta dt); void update(entityx::TimeDelta dt); template diff --git a/main.cpp b/main.cpp index a3901a3..6631736 100644 --- a/main.cpp +++ b/main.cpp @@ -129,7 +129,7 @@ int main(int argc, char *argv[]) //initInventorySprites(); // load mouse texture, and other inventory textures - mouseTex = Texture::loadTexture("assets/mouse.png"); + mouseTex = Texture::loadTexture("assets/goodmouse.png"); // get a world if (xmlFolder.empty()) @@ -227,7 +227,7 @@ int main(int argc, char *argv[]) const bool &run = game::engine.shouldRun; while (run) { render(); - game::engine.render(0); + game::engine.resetRender(0); } thMain.join(); @@ -307,6 +307,8 @@ void render() { // draw the player's inventory //player->inv->draw(); + game::engine.render(0); + // draw the fade overlay ui::drawFade(); @@ -351,7 +353,7 @@ void render() { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, mouseTex); Render::useShader(&Render::textShader); - Render::drawRect(ui::mouse, ui::mouse + 15, -9.9); + Render::drawRect(vec2(ui::mouse.x, ui::mouse.y - 64), vec2(ui::mouse.x + 64, ui::mouse.y), -9.9); Render::textShader.unuse(); } diff --git a/src/common.cpp b/src/common.cpp index 01a7db8..098cd84 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -22,6 +22,14 @@ unsigned int millis(void) { return std::chrono::duration_cast(now.time_since_epoch()).count(); } + +vec2 str2coord(std::string s) +{ + auto cpos = s.find(','); + s[cpos] = '\0'; + return vec2 (std::stof(s), std::stof(s.substr(cpos + 1))); +} + std::vector StringTokenizer(const std::string& str, char delim) { std::vector tokens; diff --git a/src/components.cpp b/src/components.cpp index 612e522..323dfc8 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -21,9 +21,9 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e if (entity.has_component() && entity.has_component()) { if (direction.x) { - entity.component().get()->sprite = entity.component().get()->nextFrame(); + entity.component()->nextFrame(entity.component()->sprite); } else { - entity.component().get()->sprite = entity.component().get()->firstFrame(); + entity.component()->firstFrame(entity.component()->sprite); } } if (entity.has_component() && entity.component()->talking) { @@ -82,38 +82,41 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, 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, - 1.0, 1.0, + float its = 0; + for (auto &S : sprite.sprite) { + auto sp = S.first; + float width = HLINES(S.first.size.x); + float height = HLINES(S.first.size.y); + vec2 drawOffset(HLINES(S.second.x), HLINES(S.second.y)); + vec2 loc(pos.x + drawOffset.x, pos.y + drawOffset.y); - 1.0, 1.0, - 0.0, 1.0, - 0.0, 0.0}; + GLfloat tex_coord[] = {sp.offset_tex.x, sp.offset_tex.y, + sp.offset_tex.x + sp.size_tex.x, sp.offset_tex.y, + sp.offset_tex.x + sp.size_tex.x, sp.offset_tex.y + sp.size_tex.y, - GLfloat tex_coordL[] = {1.0, 0.0, - 0.0, 0.0, - 0.0, 1.0, + sp.offset_tex.x + sp.size_tex.x, sp.offset_tex.y + sp.size_tex.y, + sp.offset_tex.x, sp.offset_tex.y + sp.size_tex.y, + sp.offset_tex.x, sp.offset_tex.y}; - 0.0, 1.0, - 1.0, 1.0, - 1.0, 0.0}; + if(sprite.faceLeft) { - if (entity.has_component()) - sprite.sprite = entity.component()->nextFrame(); + glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(-1.0f,1.0f,1.0f)); + glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(0-width-pos.x*2, 0.0f, 0.0f)); - for (auto &S : sprite.sprite) { - float width = HLINES(S.first.size.x); - float height = HLINES(S.first.size.y); + glm::mat4 mov = scale * translate; + glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(mov)); - vec2 loc = vec2(pos.x + S.first.offset.x, pos.y + S.first.offset.y); + } else { + + } - GLfloat coords[] = {loc.x, loc.y, visible.z, - loc.x + width, loc.y, visible.z, - loc.x + width, loc.y + height, visible.z, + GLfloat coords[] = {loc.x, loc.y, visible.z + its, + loc.x + width, loc.y, visible.z + its, + loc.x + width, loc.y + height, visible.z + its, - loc.x + width, loc.y + height, visible.z, - loc.x, loc.y + height, visible.z, - loc.x, loc.y, visible.z}; + loc.x + width, loc.y + height, visible.z + its, + loc.x, loc.y + height, visible.z + its, + loc.x, loc.y, visible.z + its}; // make the entity hit flash red @@ -129,13 +132,13 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, Render::worldShader.enable(); glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords); - if (sprite.faceLeft) - glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coordL); - else - glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord); + glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord); glDrawArrays(GL_TRIANGLES, 0, 6); + glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f))); glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0); + + its-=.01; } }); @@ -264,6 +267,10 @@ std::vector developFrame(XMLElement* xml) Frame tmpf; std::vector tmp; + vec2 foffset; + vec2 fsize; + vec2 fdraw; + // this is the xml elements first child. It will only be the tag auto framexml = xml->FirstChildElement(); while (framexml) { @@ -271,12 +278,23 @@ std::vector developFrame(XMLElement* xml) std::string defframe = framexml->Name(); if (defframe == "frame") { tmpf.clear(); + tmp.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))); + foffset = (sxml->Attribute("offset") != nullptr) ? + str2coord(sxml->Attribute("offset")) : vec2(0,0); + fdraw = (sxml->Attribute("drawOffset") != nullptr) ? + str2coord(sxml->Attribute("drawOffset")) : vec2(0,0); + + if (sxml->Attribute("size") != nullptr) { + fsize = str2coord(sxml->Attribute("size")); + tmpf.push_back(std::make_pair(SpriteData(sxml->GetText(), foffset, fsize), fdraw)); + } else { + tmpf.push_back(std::make_pair(SpriteData(sxml->GetText(), foffset), fdraw)); + } } sxml = sxml->NextSiblingElement(); } diff --git a/src/engine.cpp b/src/engine.cpp index e5b2b36..7287f7d 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -40,11 +40,14 @@ void Engine::init(void) { void Engine::render(entityx::TimeDelta dt) { systems.update(dt); - systems.update(dt); //systems.update(dt); // doesn't do anything... ui::fadeUpdate(); } +void Engine::resetRender(entityx::TimeDelta dt) +{ + systems.update(dt); +} void Engine::update(entityx::TimeDelta dt) { diff --git a/src/ui.cpp b/src/ui.cpp index 1994382..84bb55f 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -747,7 +747,7 @@ namespace ui { c2.x, c1.y + box_corner_dim.y, z, 1.0f, 0.5f, c2.x, c1.y + box_corner_dim.y, z, 1.0f, 0.5f, - c2.x - box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.0f, 0.5f, + c2.x - box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.5f, 0.5f, c2.x - box_corner_dim.x, c1.y, z, 0.5f, 0.0f}; GLfloat box_l[] = {c1.x, c1.y + box_corner_dim.y, z, 0.0f, 0.0f, diff --git a/src/world.cpp b/src/world.cpp index 4a7e284..d61ed41 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -182,11 +182,6 @@ bool WorldSystem::save(void) void WorldSystem::load(const std::string& file) { auto& render = *game::engine.getSystem(); - auto str2coord = [](std::string s) -> vec2 { - auto cpos = s.find(','); - s[cpos] = '\0'; - return vec2 (std::stof(s), std::stof(s.substr(cpos + 1))); - }; entityx::Entity entity; @@ -332,10 +327,10 @@ void WorldSystem::load(const std::string& file) entity.assign(abcd->FloatAttribute("value")); } else if (tname == "Sprite") { auto sprite = entity.assign(); - auto tex = abcd->Attribute("image"); - sprite->addSpriteSegment(SpriteData(tex, - vec2(0, 0)), - vec2(0, 0)); + auto sprx = abcd; + auto frames = developFrame(sprx); + if (frames.size()) + sprite->sprite = frames.at(0); } else if (tname == "Portal") { entity.assign(wxml->StrAttribute("inside")); } else if (tname == "Solid") { @@ -382,12 +377,20 @@ void WorldSystem::load(const std::string& file) } else if (tname == "Wander") { entity.assign(); } else if (tname == "Animation") { - entity.assign(); + auto entan = entity.assign(); auto animx = abcd->FirstChildElement(); + uint idtc = 0; while (animx) { std::string animType = animx->Name(); if (animType == "movement") { - entity.component().get()->frame = developFrame(animx); + auto frames = developFrame(animx); + if (animx->UnsignedAttribute("changeID") != XML_NO_ERROR) + idtc = 0; + else + idtc = animx->UnsignedAttribute("changeID"); + for (uint i = 0; i < frames.size(); i++) { + entan->frame.push_back(std::make_pair(idtc, frames[i])); + } } animx = animx->NextSiblingElement(); diff --git a/xml/entities.xml b/xml/entities.xml index b447dc3..e1d7549 100644 --- a/xml/entities.xml +++ b/xml/entities.xml @@ -3,71 +3,20 @@ - + image="assets/NPC.png" + + assets/NPC.png + assets/NPC.png + assets/items/ironSword.png + + - + - assets/NPC.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 - - - assets/NPC_Walk9.png - - - assets/NPC_Walk8.png - - - assets/NPC_Walk7.png - - - assets/NPC_Walk6.png - - - assets/NPC_Walk5.png - - - assets/NPC_Walk4.png - - - assets/NPC_Walk3.png - - - assets/NPC_Walk2.png - - - assets/NPC_Walk.png - - - assets/NPC.png + assets/NPC_Walk.png @@ -82,7 +31,11 @@ - + + + assets/style/classic/house1.png + + @@ -91,7 +44,11 @@ - + + + assets/chest.png + + -- 2.39.5