From d79f4a7f4b5aff5931ef86edd2537ef5e3620fd4 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 17 Oct 2017 22:21:52 -0400 Subject: arrow rotation... kinda --- src/player.cpp | 4 +++- src/systems/render.cpp | 10 ++++++++++ src/world.cpp | 10 +++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/player.cpp b/src/player.cpp index 5d4d89b..ef1752f 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -241,7 +241,9 @@ bool PlayerSystem::receive(const UseItemEvent& uie) e.assign(); auto sprite = e.assign(); auto tex = InventorySystem::getItem("Arrow"); - sprite->addSpriteSegment(SpriteData(tex->sprite), 0); + auto frame = SpriteData(tex->sprite); + frame.veltate = true; + sprite->addSpriteSegment(frame, 0); auto dim = HLINES(sprite->getSpriteSize()); e.assign(dim.x, dim.y); e.assign(uie.attack); diff --git a/src/systems/render.cpp b/src/systems/render.cpp index ce79522..a25b152 100644 --- a/src/systems/render.cpp +++ b/src/systems/render.cpp @@ -76,6 +76,16 @@ void RenderSystem::render(void) loc.x, loc.y + size.y, visible.z + its, sp.offset_tex.x, sp.offset_tex.y + sp.size_tex.y }; + if (S.first.veltate) { + auto vel = entity.component(); + float angle = static_cast(std::atan(vel->y / vel->x)) * 180 / 3.14f; + auto toOrigin = glm::translate(glm::mat4(1.0f), glm::vec3(-pos.x, -pos.y, 0.0f)); + auto rotation = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 0.0f, 1.0f)); + auto toBack = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, pos.y, 0.0f)); + auto fine = toBack * rotation * toOrigin; + glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(fine)); + } + sp.tex.use(); glUniform1i(Render::worldShader.uniform[WU_texture], 0); diff --git a/src/world.cpp b/src/world.cpp index 3455b0e..dcbc707 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -326,9 +326,14 @@ void WorldSystem::loader(void) while (abcd) { std::string tname = abcd->Name(); - if (tname == "Position") + if (tname == "Position") { entity.assign(wxml, abcd); - else if (tname == "Visible") + auto pos = entity.component(); + if (pos->x == 0 && pos->y == 0) { + pos->x = (randGet() % static_cast(world.startX * 1.9f)) + world.startX; + pos->y = 150; + } + } else if (tname == "Visible") entity.assign(wxml, abcd); else if (tname == "Sprite") entity.assign(wxml, abcd); @@ -354,7 +359,6 @@ void WorldSystem::loader(void) else if (tname == "Wander") { auto script = abcd->GetText(); entity.assign(script != nullptr ? script : ""); - //entity.component()->script.addFunction("getpos", PlayerSystem::getPosition); } else if (tname == "Hop") entity.assign(); else if (tname == "Health") -- cgit v1.2.3