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 | |
parent | 03246da32a8452e6a76ccf2f7f97cda4472d1d29 (diff) |
arrow rotation... kinda
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | assets/music/town.ogg | bin | 1791610 -> 1574715 bytes | |||
-rw-r--r-- | include/components/sprite.hpp | 2 | ||||
-rw-r--r-- | src/player.cpp | 4 | ||||
-rw-r--r-- | src/systems/render.cpp | 10 | ||||
-rw-r--r-- | src/world.cpp | 10 | ||||
-rw-r--r-- | xml/!town.xml | 1 | ||||
-rw-r--r-- | xml/entities.xml | 37 |
8 files changed, 48 insertions, 18 deletions
@@ -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 Binary files differindex 899f136..d342b78 100644 --- a/assets/music/town.ogg +++ b/assets/music/town.ogg 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<std::pair<SpriteData, vec2>>; 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") 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 @@ <structure inside="bobshouse.xml" type="1" position="10.0,100.0"/> <skirl /> <birb position="-300.0,100.0" /> + <firefly /> </World> <Dialog name="Bob"> 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 @@ <spawnx/> +<firefly> + <Position /> + <Visible value="0.1" /> + <Sprite> + <frame> + <src limb="0" offset="0,5" size="1,1" drawOffset="0,0">assets/colorIndex.png</src> + </frame> + </Sprite> + <Direction /> + <Solid /> + <Wander> + 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 + </Wander> +</firefly> + <npc> <Position value="0.0,100.0" /> <Visible value="0.2" /> @@ -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 </Wander> <Aggro/> @@ -122,7 +134,6 @@ <Solid /> <Physics /> <Name value="birb" /> - <Health value="60" /> <Wander> countdown = 0 onetime = 0 |