diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-01-14 09:56:58 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-01-14 09:56:58 -0500 |
commit | 3da25ab8c6ad1b52b808bfeffc0ad1b32621cfac (patch) | |
tree | a034097efd9965e64efcf55ea1d9a2548ee0f927 /src | |
parent | f91e95eed85bdd74b219b20a435fa6f297069da1 (diff) |
particle improvements, inventory start
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 2 | ||||
-rw-r--r-- | src/inventory.cpp | 89 | ||||
-rw-r--r-- | src/particle.cpp | 48 | ||||
-rw-r--r-- | src/render.cpp | 12 | ||||
-rw-r--r-- | src/world.cpp | 13 |
5 files changed, 108 insertions, 56 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index c7999ed..d334aea 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -23,7 +23,7 @@ void Engine::init(void) { systems.add<WindowSystem>(); systems.add<RenderSystem>(); systems.add<InputSystem>(); - //systems.add<InventorySystem>(); + systems.add<InventorySystem>(); systems.add<WorldSystem>(); systems.add<PlayerSystem>(); systems.add<QuestSystem>(); diff --git a/src/inventory.cpp b/src/inventory.cpp index ed6028b..de18104 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -2,23 +2,59 @@ #include <common.hpp> #include <events.hpp> -//#include <texture.hpp> -//#include <render.hpp> +#include <texture.hpp> +#include <render.hpp> -constexpr const char* iconTexturePath = "config/invIcons.txt"; +#include <deque> -static std::vector<Texture> iconTextures; +#include <tinyxml2.h> +using namespace tinyxml2; + +constexpr const char* itemsPath = "config/items.xml"; + + +struct Item { + std::string name; + std::string type; + int value; + int stackSize; + Texture sprite; + + Item(void) + : value(0), stackSize(1) {} + + Item(XMLElement *e) { + name = e->StrAttribute("name"); + type = e->StrAttribute("type"); + + value = 0; + e->QueryIntAttribute("value", &value); + stackSize = 1; + e->QueryIntAttribute("maxStackSize", &stackSize); + + sprite = Texture(e->StrAttribute("sprite")); + } +}; + +static std::deque<Item> itemList; void InventorySystem::configure(entityx::EventManager &ev) { ev.subscribe<KeyDownEvent>(*this); } -void InventorySystem::loadIcons(void) { - iconTextures.clear(); - auto icons = readFileA(iconTexturePath); - for (const auto& s : icons) - iconTextures.push_back(s); +void InventorySystem::loadItems(void) { + XMLDocument doc; + doc.LoadFile(itemsPath); + + auto item = doc.FirstChildElement("item"); + if (item == nullptr) + UserError("No items found"); + + do { + itemList.emplace_back(item); + item = item->NextSiblingElement("item"); + } while (item != nullptr); } void InventorySystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) @@ -26,20 +62,35 @@ void InventorySystem::update(entityx::EntityManager &en, entityx::EventManager & (void)en; (void)ev; (void)dt; +} - // TODO TODO TODO TODO until we do something - return; +void InventorySystem::render(void) +{ + Render::textShader.use(); + Render::textShader.enable(); + Colors::black.use(); + glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, .8); - //vec2 start = vec2(offset.x, 100);// - game::SCREEN_WIDTH / 2 + 20, game::SCREEN_HEIGHT - 40); + // calculate positions + items.front().loc = vec2(offset.x - 35 * items.size(), offset.y - game::SCREEN_HEIGHT / 2); + for (unsigned int i = 1; i < items.size(); i++) + items[i].loc = vec2(items[i - 1].loc.x + 70, items[i - 1].loc.y); - //std::cout << start.x << ' ' << start.y << std::endl; + // draw items + for (const auto& i : items) { + glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, Colors::texCoord); + vec2 end = i.loc + 64; + GLfloat coords[18] = { + i.loc.x, i.loc.y, -9, end.x, i.loc.y, -9, end.x, end.y, -9, + end.x, end.y, -9, i.loc.x, end.y, -9, i.loc.x, i.loc.y, -9 + }; + glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords); + glDrawArrays(GL_TRIANGLES, 0, 6); + } - /*Render::textShader.use(); - glActiveTexture(GL_TEXTURE0); - Colors::black.use(); - Render::useShader(&Render::textShader); - Render::drawRect(start, start + 20, -9.9f); - Render::textShader.unuse();*/ + glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1); + Render::textShader.disable(); + Render::textShader.unuse(); } void InventorySystem::receive(const KeyDownEvent &kde) diff --git a/src/particle.cpp b/src/particle.cpp index 2d92409..198387c 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -91,52 +91,54 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e auto& p = parts[i]; // update timers - p.timeLeft -= dt; + if (p.timeLeft > 0) + p.timeLeft -= dt; + else + continue; // update movement + auto& vel = p.velocity; switch (p.type) { case ParticleType::Drop: - if (p.velocity.y > -.6) - p.velocity.y -= 0.001f; + if (vel.y > -.6) + vel.y -= 0.001f; break; case ParticleType::Confetti: - if (p.velocity.x > -0.01 && p.velocity.x < 0.01) { - p.velocity.x = randGet() % 12 / 30.0f - 0.2f; + if (vel.x > -0.01 && vel.x < 0.01) { + vel.x = randGet() % 12 / 30.0f - 0.2f; + vel.y = -0.15f; } else { - p.velocity.x += (p.velocity.x > 0) ? -0.002f : 0.002f; + vel.x += (vel.x > 0) ? -0.002f : 0.002f; } - p.velocity.y = -0.15f; - p.timeLeft = 1000; break; case ParticleType::SmallBlast: - if (p.velocity.x == 0) { + if (vel.x == 0) { int degree = randGet() % 100; - p.velocity.x = cos(degree) / 4.0f; - p.velocity.y = sin(degree) / 4.0f; + vel.x = cos(degree) / 4.0f; + vel.y = sin(degree) / 4.0f; } else { - p.velocity.x += (p.velocity.x > 0) ? -0.001f : 0.001f; - p.velocity.y += (p.velocity.y > 0) ? -0.001f : 0.001f; - if ((p.velocity.x > -0.01 && p.velocity.x < 0.01) && - (p.velocity.y > -0.01 && p.velocity.y < 0.01)) { + vel.x += (vel.x > 0) ? -0.001f : 0.001f; + vel.y += (vel.y > 0) ? -0.001f : 0.001f; + if ((vel.x > -0.01 && vel.x < 0.01) && + (vel.y > -0.01 && vel.y < 0.01)) { p.timeLeft = 0; } } - break; case ParticleType::SmallPoof: - if (p.velocity.x == 0) { - p.velocity.y = 0.1f; - p.velocity.x = randGet() % 10 / 20.0f - 0.25f; + if (vel.x == 0) { + vel.y = 0.1f; + vel.x = randGet() % 10 / 20.0f - 0.25f; } else { - p.velocity.x += (p.velocity.x > 0) ? -0.001f : 0.001f; - p.velocity.y -= 0.0015f; + vel.x += (vel.x > 0) ? -0.001f : 0.001f; + vel.y -= 0.0015f; } break; } // really update movement - p.location.x += p.velocity.x * dt; - p.location.y += p.velocity.y * dt; + p.location.x += vel.x * dt; + p.location.y += vel.y * dt; // world collision auto height = worldSystem.isAboveGround(p.location); diff --git a/src/render.cpp b/src/render.cpp index 4e32311..a63d63a 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -99,14 +99,16 @@ void render(const int& fps) } // namespace render -#include <ui.hpp> -#include <window.hpp> -#include <world.hpp> #include <engine.hpp> +#include <gametime.hpp> +#include <inventory.hpp> #include <particle.hpp> #include <player.hpp> +#include <ui.hpp> +#include <window.hpp> +#include <world.hpp> + #include <entityx/entityx.h> -#include <gametime.hpp> void preRender(void) { @@ -172,6 +174,8 @@ void render(const int& fps) game::engine.getSystem<RenderSystem>()->render(); + game::engine.getSystem<InventorySystem>()->render(); + // draw the debug overlay if desired if (ui::debug) { auto pos = game::engine.getSystem<PlayerSystem>()->getPosition(); diff --git a/src/world.cpp b/src/world.cpp index 8f4be8e..43b66cd 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -98,14 +98,6 @@ static const std::string buildPaths[] = { "brazzier.png" }; -// alpha-related values used for world drawing? nobody knows... -static const float bgDraw[4][3]={ - { 100, 240, 0.6 }, - { 150, 250, 0.4 }, - { 200, 255, 0.25 }, - { 255, 255, 0.1 } -}; - /* ---------------------------------------------------------------------------- ** Functions section ** --------------------------------------------------------------------------*/ @@ -827,9 +819,12 @@ void WorldSystem::render(void) Render::worldShader.unuse(); // draw the remaining layers + static const float alphas[4] = { + 0.6, 0.4, 0.25, 0.1 + }; for (int i = 0; i < 4; i++) { bgTex++; - auto xcoord = offset.x * bgDraw[i][2]; + auto xcoord = offset.x * alphas[i]; bg_items.clear(); bg_tex.clear(); |