From 51629a66ff14a9025d9bd9ea69831e3d824a0760 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 30 Apr 2017 16:16:41 -0400 Subject: mem track+, drop func. added --- src/inventory.cpp | 46 +++++++++++++++++++++++++++++++++------------- src/player.cpp | 2 +- src/world.cpp | 15 +++++++-------- 3 files changed, 41 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/inventory.cpp b/src/inventory.cpp index 434eac6..96c1d6d 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -219,25 +219,45 @@ void InventorySystem::receive(const MouseReleaseEvent &mre) } } - auto e = game::entities.create(); - e.assign(mre.position.x, mre.position.y); - e.assign(0, 0.1f); - e.assign(items[movingItem]); - e.assign(); - e.component()->addSpriteSegment( - SpriteData(items[movingItem].item->sprite), vec2(0, 0)); - auto dim = items[movingItem].item->sprite.getDim(); - e.assign(HLINES(dim.x), HLINES(dim.y)); - e.assign(); - e.assign(); - + makeDrop(mre.position, items[movingItem]); items[movingItem].item = nullptr; items[movingItem].count = 0; - movingItem = -1; } } +void InventorySystem::makeDrop(const vec2& p, InventoryEntry& ie) +{ + auto e = game::entities.create(); + e.assign(p.x, p.y); + e.assign(0, 0.1f); + e.assign(ie); + e.assign(); + e.component()->addSpriteSegment( + SpriteData(ie.item->sprite), vec2(0, 0)); + auto dim = ie.item->sprite.getDim(); + e.assign(HLINES(dim.x), HLINES(dim.y)); + e.assign(); + e.assign(); +} + +void InventorySystem::makeDrop(const vec2& p, const std::string& s, int c) +{ + auto item = getItem(s); + auto e = game::entities.create(); + e.assign(p.x, p.y); + e.assign(0, 0.1f); + InventoryEntry ie (item, c); + e.assign(ie); + e.assign(); + e.component()->addSpriteSegment( + SpriteData(item->sprite), vec2(0, 0)); + auto dim = item->sprite.getDim(); + e.assign(HLINES(dim.x), HLINES(dim.y)); + e.assign(); + e.assign(); +} + void InventorySystem::receive(const KeyDownEvent &kde) { if (kde.keycode == SDLK_e) { diff --git a/src/player.cpp b/src/player.cpp index 0256190..01b8a7c 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -245,7 +245,7 @@ void PlayerSystem::receive(const UseItemEvent& uie) e.assign(); auto sprite = e.assign(); auto tex = InventorySystem::getItem("Arrow"); - sprite->addSpriteSegment(SpriteData(tex.sprite), 0); + sprite->addSpriteSegment(SpriteData(tex->sprite), 0); auto dim = HLINES(sprite->getSpriteSize()); e.assign(dim.x, dim.y); e.assign(10, false); diff --git a/src/world.cpp b/src/world.cpp index bf34973..912a0c9 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -669,14 +669,13 @@ void WorldSystem::render(void) //glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.3 - static_cast(alpha) / 255.0f); //makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions(0, fron_tex_coord, tex_coord, 6); - // TODO make stars dynamic (make them particles??) - static const Texture starTex ("assets/style/classic/bg/star.png"); // TODO why in theme, not just std.? - const static float stardim = 24; - GLfloat* star_coord = new GLfloat[stars.size() * 5 * 6 + 1]; - GLfloat* si = &star_coord[0]; - if (worldShade > 0) { + static const Texture starTex ("assets/style/classic/bg/star.png"); // TODO why in theme, not just std.? + static const float stardim = 24; + + GLfloat* star_coord = new GLfloat[stars.size() * 5 * 6 + 1]; + auto si = &star_coord; auto xcoord = offset.x * 0.9f; for (auto &s : stars) { @@ -698,9 +697,9 @@ void WorldSystem::render(void) glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &star_coord[0]); glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &star_coord[3]); glDrawArrays(GL_TRIANGLES, 0, stars.size() * 6); - } - delete[] star_coord; + delete[] star_coord; + } Render::worldShader.disable(); -- cgit v1.2.3