diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-03-14 18:19:06 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-03-14 18:19:06 -0400 |
commit | ba651a82d585c181e9632fadba5bb4d683842d44 (patch) | |
tree | 8b2711866d497dfd471903c603e2f33bd4a41a5a /src | |
parent | a7d7d7e687cde01ed2d2ec2adb6ee5bfff8bbddc (diff) |
better slash, scale fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/attack.cpp | 9 | ||||
-rw-r--r-- | src/components.cpp | 2 | ||||
-rw-r--r-- | src/inventory.cpp | 37 | ||||
-rw-r--r-- | src/particle.cpp | 8 | ||||
-rw-r--r-- | src/world.cpp | 4 |
5 files changed, 48 insertions, 12 deletions
diff --git a/src/attack.cpp b/src/attack.cpp index 226fe2f..525b0c3 100644 --- a/src/attack.cpp +++ b/src/attack.cpp @@ -33,11 +33,12 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev, (void)e; if (e.has_component<Player>()) return; - vec2 eloc (pos.x + dim.width / 2, pos.y + dim.height / 2); - if (abs(eloc.x - a.pos.x) <= shortSlashLength) { + + if ((pos.x > a.pos.x && pos.x < a.pos.x + shortSlashLength) || + (pos.x + dim.width < a.pos.x && pos.x + dim.width > a.pos.x - shortSlashLength)) { h.health -= a.power; - game::engine.getSystem<ParticleSystem>()->addMultiple(10, ParticleType::SmallBlast, - [&](){ return eloc; }, 500, 7); + game::engine.getSystem<ParticleSystem>()->addMultiple(10, ParticleType::DownSlash, + [&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7); } } ); diff --git a/src/components.cpp b/src/components.cpp index a711f45..af746ab 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -106,7 +106,7 @@ Texture RenderSystem::loadTexture(const std::string& file) void RenderSystem::render(void) { if (!loadTexString.empty()) { - loadTexResult = Texture(loadTexString, true); + loadTexResult = Texture(loadTexString, false); loadTexString.clear(); } diff --git a/src/inventory.cpp b/src/inventory.cpp index 3995e3a..d669c00 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -4,6 +4,7 @@ #include <components.hpp> #include <engine.hpp> #include <error.hpp> +#include <player.hpp> #include <render.hpp> #include <ui.hpp> @@ -78,6 +79,8 @@ void InventorySystem::render(void) size = hotbarSize; } + static const GLfloat tex[12] = {0,1,1,1,1,0,1,0,0,0,0,1}; + // draw items for (int n = 0; n < size; n++) { auto &i = items[n]; @@ -101,11 +104,18 @@ void InventorySystem::render(void) // draw the item if (i.item != nullptr && i.count > 0) { i.item->sprite.use(); - static const GLfloat tex[12] = {0,1,1,1,1,0,1,0,0,0,0,1}; glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex); - vec2 sta ((n == movingItem) ? ui::mouse - i.item->sprite.getDim() / 2 : i.loc); - vec2 end = (n == movingItem) ? ui::mouse + i.item->sprite.getDim() / 2 : i.loc + i.item->sprite.getDim(); + auto& dim = i.item->sprite.getDim(); + vec2 truDim; + if (dim.x >= dim.y) + truDim.x = entrySize - 6, truDim.y = truDim.x * dim.y / dim.x; + else + truDim.y = entrySize - 6, truDim.x = truDim.y * dim.x / dim.y; + + vec2 loc (i.loc.x + ((entrySize - 6) / 2 - truDim.x / 2), i.loc.y); + vec2 sta ((n == movingItem) ? ui::mouse - truDim / 2 : loc); + vec2 end = (n == movingItem) ? ui::mouse + truDim / 2 : loc + truDim; GLfloat coords[18] = { sta.x, sta.y, inventoryZ - 0.2, end.x, sta.y, inventoryZ - 0.2, end.x, end.y, inventoryZ - 0.2, end.x, end.y, inventoryZ - 0.2, sta.x, end.y, inventoryZ - 0.2, sta.x, sta.y, inventoryZ - 0.2 @@ -115,12 +125,31 @@ void InventorySystem::render(void) glUniform4f(Render::textShader.uniform[WU_tex_color], .8, .8, 1, .8); glDrawArrays(GL_TRIANGLES, 0, 6); ui::setFontZ(inventoryZ - 0.3); // TODO fix z's - ui::putText(sta.x, sta.y, std::to_string(i.count).c_str()); + ui::putText(i.loc.x, i.loc.y, std::to_string(i.count).c_str()); ui::setFontZ(-6); glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1); } } + if (items[0].item != nullptr && items[0].count > 0) { + Render::textShader.use(); + Render::textShader.enable(); + + auto& i = items[0]; + i.item->sprite.use(); + glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex); + + auto pos = game::engine.getSystem<PlayerSystem>()->getPosition(); + vec2 sta (pos.x, pos.y); + vec2 end (sta + (i.item->sprite.getDim() * game::HLINE)); + GLfloat coords[18] = { + sta.x, sta.y, -8, end.x, sta.y, -8, end.x, end.y, -8, + end.x, end.y, -8, sta.x, end.y, -8, sta.x, sta.y, -8 + }; + glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords); + glDrawArrays(GL_TRIANGLES, 0, 6); + } + Render::textShader.disable(); Render::textShader.unuse(); } diff --git a/src/particle.cpp b/src/particle.cpp index 52d0b23..02f3640 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -140,13 +140,19 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e break; case ParticleType::SmallPoof: if (vel.x == 0) { - vel.y = 0.1f; vel.x = randGet() % 10 / 20.0f - 0.25f; + vel.y = 0.1f; } else { vel.x += (vel.x > 0) ? -0.001f : 0.001f; vel.y -= 0.0015f; } break; + case ParticleType::DownSlash: + if (vel.x == 0) { + vel.x = 0.2f * (randGet() % 16 - 8) / 10.0f; + vel.y = -vel.x; + } + break; } // really update movement diff --git a/src/world.cpp b/src/world.cpp index f4be288..9a47576 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -173,10 +173,10 @@ void WorldSystem::fight(entityx::Entity entity) door.assign<Portal>(exit); auto sprite = door.assign<Sprite>(); - Texture dtex ("assets/style/classic/door.png"); + auto dtex = game::engine.getSystem<RenderSystem>()->loadTexture("assets/style/classic/door.png"); sprite->addSpriteSegment(SpriteData(dtex), 0); - auto dim = sprite->getSpriteSize(); + auto dim = HLINES(sprite->getSpriteSize()); door.assign<Solid>(dim.x, dim.y); } |