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 --- Makefile | 2 +- assets/music/town.ogg | Bin 1791610 -> 1574715 bytes include/components/sprite.hpp | 2 ++ src/player.cpp | 4 +++- src/systems/render.cpp | 10 ++++++++++ src/world.cpp | 10 +++++++--- xml/!town.xml | 1 + xml/entities.xml | 37 ++++++++++++++++++++++++------------- 8 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index f8210e4..2cc8f31 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ ifeq ($(TARGET_OS),win32) endif CXXFLAGS = -ggdb -m$(TARGET_BITS) -std=c++17 -fext-numeric-literals -CXXINC = -Iinclude -Iinclude/freetype -Iinclude/lua -I. +CXXINC = -Iinclude -Iinclude/freetype -I. CXXWARN = -Wall -Wextra -Werror -pedantic CXXSRCDIR = src diff --git a/assets/music/town.ogg b/assets/music/town.ogg index 899f136..d342b78 100644 Binary files a/assets/music/town.ogg and b/assets/music/town.ogg differ diff --git a/include/components/sprite.hpp b/include/components/sprite.hpp index 35a13b8..0617620 100644 --- a/include/components/sprite.hpp +++ b/include/components/sprite.hpp @@ -22,6 +22,8 @@ struct SpriteData { vec2 size_tex; unsigned int limb; + + bool veltate = false; }; using Frame = std::vector>; 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") diff --git a/xml/!town.xml b/xml/!town.xml index 07d84ac..a038bee 100644 --- a/xml/!town.xml +++ b/xml/!town.xml @@ -23,6 +23,7 @@ + diff --git a/xml/entities.xml b/xml/entities.xml index 16bee0f..921e837 100644 --- a/xml/entities.xml +++ b/xml/entities.xml @@ -1,5 +1,29 @@ + + + + + + assets/colorIndex.png + + + + + + countdown = 0 + + update = function() + if (countdown == 0) then + countdown = math.random(100, 500) + velx = math.random(-5, 5) * 0.001 + vely = math.random(-5, 5) * 0.001 + end + countdown = countdown - 1 + end + + + @@ -80,10 +104,6 @@ countdown = 0 update = function() - if (velx < 0 and math.abs(selfx - playerx) < 150) then - aggro = 1 - end - if (countdown == 0) then countdown = math.random(3000, 5000) velx = math.random(-1, 1) * 0.005 @@ -92,15 +112,7 @@ end hostile = function() - if (playerx <= selfx) then - velx = -0.01 - else - velx = 0.01 - end - if (math.abs(playerx - selfx) < 50) then - attack(selfx, selfy) - end end @@ -122,7 +134,6 @@ - countdown = 0 onetime = 0 -- cgit v1.2.3