]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
arrow rotation... kinda
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 18 Oct 2017 02:21:52 +0000 (22:21 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 18 Oct 2017 02:21:52 +0000 (22:21 -0400)
Makefile
assets/music/town.ogg
include/components/sprite.hpp
src/player.cpp
src/systems/render.cpp
src/world.cpp
xml/!town.xml
xml/entities.xml

index f8210e4ceebb6f45c2d69c550ebaeaa5a353ee31..2cc8f31174b4105511c07aa2e85c821653e49146 100644 (file)
--- 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
index 899f1360aaf5cfdd7d2ac2996d8ac8ec3f2c827c..d342b789aaf0054bf13cad4487036d1bc7665b6c 100644 (file)
Binary files a/assets/music/town.ogg and b/assets/music/town.ogg differ
index 35a13b82c45bb4ab5ccec402411c999745997bb4..0617620463107b93e9892b9661b8e8f0df82a128 100644 (file)
@@ -22,6 +22,8 @@ struct SpriteData {
        vec2 size_tex;
 
        unsigned int limb;
+
+       bool veltate = false;
 };
 
 using Frame = std::vector<std::pair<SpriteData, vec2>>;
index 5d4d89b27977e14daa10d28115f90be68934f59e..ef1752f74513d414fc08dbfd5e8bdf3bc7aa6661 100644 (file)
@@ -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);
index ce795226a7cf7e1dc93081a308796ea3818ca142..a25b152bd97f2f339f826e310219095bebafd336 100644 (file)
@@ -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);
index 3455b0e3f05da344ad88a5af94e1d8aa12807fe4..dcbc707f7377a15243d2920aa1743bce34ec0a6d 100644 (file)
@@ -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")
index 07d84acc5693af9d6ba9038c42cbc854c789be17..a038bee36922d54373ceec1bbbff495f9109e537 100644 (file)
@@ -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">
index 16bee0f4a5ca0c450e6537288a6e6bdf909acadc..921e83719733c5e55db5fd5a11768a70c5b65d2b 100644 (file)
@@ -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" />
                countdown = 0
 
                update = function()
-                       if (velx &lt; 0 and math.abs(selfx - playerx) &lt; 150) then
-                               aggro = 1
-                       end
-
                        if (countdown == 0) then
                                countdown = math.random(3000, 5000)
                                velx = math.random(-1, 1) * 0.005
                end
 
                hostile = function()
-                       if (playerx &lt;= selfx) then
-                               velx = -0.01
-                       else
-                               velx = 0.01
-                       end
 
-                       if (math.abs(playerx - selfx) &lt; 50) then
-                               attack(selfx, selfy)
-                       end
                end
        </Wander>
        <Aggro/>
        <Solid />
        <Physics />
        <Name value="birb" />
-       <Health value="60" />
        <Wander>
                countdown = 0
                onetime = 0