diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-10-17 22:21:52 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-10-17 22:21:52 -0400 |
commit | d79f4a7f4b5aff5931ef86edd2537ef5e3620fd4 (patch) | |
tree | 2ad2d8a9ed9ffee36474fb111f4654511f0717b4 /src | |
parent | 03246da32a8452e6a76ccf2f7f97cda4472d1d29 (diff) |
arrow rotation... kinda
Diffstat (limited to 'src')
-rw-r--r-- | src/player.cpp | 4 | ||||
-rw-r--r-- | src/systems/render.cpp | 10 | ||||
-rw-r--r-- | src/world.cpp | 10 |
3 files changed, 20 insertions, 4 deletions
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<Physics>(); auto sprite = e.assign<Sprite>(); 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<Solid>(dim.x, dim.y); e.assign<Hit>(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<Direction>(); + float angle = static_cast<float>(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<Position>(wxml, abcd); - else if (tname == "Visible") + auto pos = entity.component<Position>(); + if (pos->x == 0 && pos->y == 0) { + pos->x = (randGet() % static_cast<int>(world.startX * 1.9f)) + world.startX; + pos->y = 150; + } + } else if (tname == "Visible") entity.assign<Visible>(wxml, abcd); else if (tname == "Sprite") entity.assign<Sprite>(wxml, abcd); @@ -354,7 +359,6 @@ void WorldSystem::loader(void) else if (tname == "Wander") { auto script = abcd->GetText(); entity.assign<Wander>(script != nullptr ? script : ""); - //entity.component<Wander>()->script.addFunction("getpos", PlayerSystem::getPosition); } else if (tname == "Hop") entity.assign<Hop>(); else if (tname == "Health") |