]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
better slash, scale fixes
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 14 Mar 2017 22:19:06 +0000 (18:19 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 14 Mar 2017 22:19:06 +0000 (18:19 -0400)
12 files changed:
include/components.hpp
include/components/all.hpp [new file with mode: 0644]
include/components/base.hpp [new file with mode: 0644]
include/components/damage.hpp [new file with mode: 0644]
include/particle.hpp
include/vector2.hpp
main.cpp
src/attack.cpp
src/components.cpp
src/inventory.cpp
src/particle.cpp
src/world.cpp

index 2215a646af8383f415685c9f8c4083ded84caea9..3f0686763bc296cae529588c22c76b6c95b56cdd 100644 (file)
 #include <tinyxml2.h>
 using namespace tinyxml2;
 
-/**
- * @class Component
- * @brief A base class for all components, insures all components have similar
- * base functionalities.
- */
-class Component : public entityx::Component<Component> {
-public:
-       /**
-        * Constructs the component from the two given XML tags.
-        *
-        * Components can get information from two places: where the entity is defined
-        * (it's implementation, e.g. in town.xml) or from the tag's definition (e.g. entities.xml).
-        * The definition tag should be used for default values.
-        *
-        * @param imp tag for the implementation of the entity
-        * @param def tag for the definition of the component
-        */
-       virtual void fromXML(XMLElement* imp, XMLElement* def) = 0;
-};
+//  TODO heyyy guys
+#include <components/all.hpp>
 
 /**
  * @struct Position
diff --git a/include/components/all.hpp b/include/components/all.hpp
new file mode 100644 (file)
index 0000000..ecba09f
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef COMPONENTS_ALL_HPP_
+#define COMPONENTS_ALL_HPP_
+
+#include "damage.hpp"
+
+#endif // COMPONENTS_ALL_HPP_
diff --git a/include/components/base.hpp b/include/components/base.hpp
new file mode 100644 (file)
index 0000000..9139a75
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef COMPONENTS_BASE_HPP_
+#define COMPONENTS_BASE_HPP_
+
+#include <entityx/entityx.h>
+#include <tinyxml2.h>
+
+using namespace tinyxml2;
+
+/**
+ * @class Component
+ * @brief A base class for all components, insures all components have similar
+ * base functionalities.
+ */
+class Component : public entityx::Component<Component> {
+public:
+       /**
+        * Constructs the component from the two given XML tags.
+        *
+        * Components can get information from two places: where the entity is defined
+        * (it's implementation, e.g. in town.xml) or from the tag's definition (e.g. entities.xml).
+        * The definition tag should be used for default values.
+        *
+        * @param imp tag for the implementation of the entity
+        * @param def tag for the definition of the component
+        */
+       virtual void fromXML(XMLElement* imp, XMLElement* def) = 0;
+};
+
+#endif // COMPONENTS_BASE_APP_
diff --git a/include/components/damage.hpp b/include/components/damage.hpp
new file mode 100644 (file)
index 0000000..c257426
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef COMPONENTS_DAMAGE_HPP_
+#define COMPONENTS_DAMAGE_HPP_
+
+#include "base.hpp"
+
+struct Damage : public Component {
+       Damage(int p = 0)
+               : pain(p) {}
+       Damage(XMLElement* imp, XMLElement* def) {
+               fromXML(imp, def);
+       }
+
+       int pain;
+
+       void fromXML(XMLElement* imp, XMLElement* def) final {
+               (void)imp;
+               if (def->QueryIntAttribute("value", &pain) != XML_NO_ERROR)
+                       pain = 0;
+       }
+};
+
+#endif // COMPONENTS_DAMAGE_HPP_
index f49e055ebe48f5a64ba89e37537ed44ebee2a260..822ac41a47deaaaa9bdcaaa6a7cac3e446299caf 100644 (file)
@@ -9,10 +9,11 @@
 #include <entityx/entityx.h>
 
 enum class ParticleType : char {
-       Drop       = 1,
-       Confetti   = 2,
-       SmallBlast = 4,
-       SmallPoof  = 8
+       Drop,
+       Confetti,
+       SmallBlast,
+       SmallPoof,
+       DownSlash
 };
 
 struct Particle {
index 828654c352a7376e3207709f8afa99e55f89796f..5671ccd71a28166c739fa724410d997698f8b25a 100644 (file)
@@ -57,6 +57,11 @@ struct vector2 {
                return vector2<T>(x * n, y * n);
        }
 
+       vector2<T> operator*=(const T& n) {
+               x *= n, y *= n;
+               return *this;
+       }
+
        // division
        vector2<T> operator/(const vector2<T>& v) const {
                return vector2<T>(x / v.x, y / v.y);
index e0bb5d2ac2fede8f89530490ee01d76d0c25aeb1..3d82c44c8905855cf932c5344230b97b5be02b58 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
        /////////////////////////////
 
 
-       game::engine.getSystem<InventorySystem>()->add("Debug", 9);
+       game::engine.getSystem<InventorySystem>()->add("Wood Sword", 9);
 
        std::list<SDL_Event> eventQueue;
 
index 226fe2f5911b14da8b0e81e45eaab1e306d47600..525b0c3e56de168e00b44bd824bffbee6fade45c 100644 (file)
@@ -33,11 +33,12 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
                                        (void)e;
                                        if (e.has_component<Player>())
                                                return;
-                                       vec2 eloc (pos.x + dim.width / 2, pos.y + dim.height / 2);
-                                       if (abs(eloc.x - a.pos.x) <= shortSlashLength) {
+
+                                       if ((pos.x > a.pos.x && pos.x < a.pos.x + shortSlashLength) || 
+                                               (pos.x + dim.width < a.pos.x && pos.x + dim.width > a.pos.x - shortSlashLength)) {
                                                h.health -= a.power;
-                                               game::engine.getSystem<ParticleSystem>()->addMultiple(10, ParticleType::SmallBlast,
-                                                       [&](){ return eloc; }, 500, 7);
+                                               game::engine.getSystem<ParticleSystem>()->addMultiple(10, ParticleType::DownSlash,
+                                                       [&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7);
                                        }
                                }
                        );
index a711f45d2c81be60d4a8db7ebc5b6acd6418590e..af746abc0f7c6034c15d1c819ee1d0f148ab41b7 100644 (file)
@@ -106,7 +106,7 @@ Texture RenderSystem::loadTexture(const std::string& file)
 void RenderSystem::render(void)
 {
        if (!loadTexString.empty()) {
-               loadTexResult = Texture(loadTexString, true);
+               loadTexResult = Texture(loadTexString, false);
                loadTexString.clear();
        }
        
index 3995e3ab71c7628973111266df21a0404c62ae86..d669c00f4599c81483308a98117b8112f1c54e07 100644 (file)
@@ -4,6 +4,7 @@
 #include <components.hpp>
 #include <engine.hpp>
 #include <error.hpp>
+#include <player.hpp>
 #include <render.hpp>
 #include <ui.hpp>
 
@@ -78,6 +79,8 @@ void InventorySystem::render(void)
                size = hotbarSize;
        }
 
+       static const GLfloat tex[12] = {0,1,1,1,1,0,1,0,0,0,0,1};
+
        // draw items
        for (int n = 0; n < size; n++) {
                auto &i = items[n];
@@ -101,11 +104,18 @@ void InventorySystem::render(void)
                // draw the item
                if (i.item != nullptr && i.count > 0) {
                        i.item->sprite.use();
-                       static const GLfloat tex[12] = {0,1,1,1,1,0,1,0,0,0,0,1};
                        glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
 
-                       vec2 sta ((n == movingItem) ? ui::mouse - i.item->sprite.getDim() / 2 : i.loc);
-                       vec2 end = (n == movingItem) ? ui::mouse + i.item->sprite.getDim() / 2 : i.loc + i.item->sprite.getDim();
+                       auto& dim = i.item->sprite.getDim();
+                       vec2 truDim;
+                       if (dim.x >= dim.y)
+                               truDim.x = entrySize - 6, truDim.y = truDim.x * dim.y / dim.x;
+                       else
+                               truDim.y = entrySize - 6, truDim.x = truDim.y * dim.x / dim.y;
+
+                       vec2 loc (i.loc.x + ((entrySize - 6) / 2 - truDim.x / 2), i.loc.y);
+                       vec2 sta ((n == movingItem) ? ui::mouse - truDim / 2 : loc);
+                       vec2 end = (n == movingItem) ? ui::mouse + truDim / 2 : loc + truDim;
                        GLfloat coords[18] = {
                                sta.x, sta.y, inventoryZ - 0.2, end.x, sta.y, inventoryZ - 0.2, end.x, end.y, inventoryZ - 0.2,
                                end.x, end.y, inventoryZ - 0.2, sta.x, end.y, inventoryZ - 0.2, sta.x, sta.y, inventoryZ - 0.2
@@ -115,12 +125,31 @@ void InventorySystem::render(void)
                                glUniform4f(Render::textShader.uniform[WU_tex_color], .8, .8, 1, .8);
                        glDrawArrays(GL_TRIANGLES, 0, 6);
                        ui::setFontZ(inventoryZ - 0.3); // TODO fix z's
-                       ui::putText(sta.x, sta.y, std::to_string(i.count).c_str());
+                       ui::putText(i.loc.x, i.loc.y, std::to_string(i.count).c_str());
                        ui::setFontZ(-6);
                        glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1);
                }
        }
 
+       if (items[0].item != nullptr && items[0].count > 0) {
+               Render::textShader.use();
+               Render::textShader.enable();
+               
+               auto& i = items[0];
+               i.item->sprite.use();
+               glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
+
+               auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
+               vec2 sta (pos.x, pos.y);
+               vec2 end (sta + (i.item->sprite.getDim() * game::HLINE));
+               GLfloat coords[18] = {
+                       sta.x, sta.y, -8, end.x, sta.y, -8, end.x, end.y, -8,
+                       end.x, end.y, -8, sta.x, end.y, -8, sta.x, sta.y, -8
+               };
+               glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords);
+               glDrawArrays(GL_TRIANGLES, 0, 6);
+       }
+
        Render::textShader.disable();
        Render::textShader.unuse();
 }
index 52d0b23631a94fe325bf0ab55846c49dacfd35c5..02f36401375b22e6b768ada1ef2efc67cb023049 100644 (file)
@@ -140,13 +140,19 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                        break;
                case ParticleType::SmallPoof:
                        if (vel.x == 0) {
-                               vel.y = 0.1f;
                                vel.x = randGet() % 10 / 20.0f - 0.25f;
+                               vel.y = 0.1f;
                        } else {
                                vel.x += (vel.x > 0) ? -0.001f : 0.001f;
                                vel.y -= 0.0015f;
                        }
                        break;
+               case ParticleType::DownSlash:
+                       if (vel.x == 0) {
+                               vel.x = 0.2f * (randGet() % 16 - 8) / 10.0f;
+                               vel.y = -vel.x;
+                       }
+                       break;
                }
 
                // really update movement
index f4be288e2f31db2aa5d80b82a6cc2fd09301f185..9a475766295a2396e12d9621c8abb4f1d3b522d9 100644 (file)
@@ -173,10 +173,10 @@ void WorldSystem::fight(entityx::Entity entity)
        door.assign<Portal>(exit);
 
        auto sprite = door.assign<Sprite>();
-       Texture dtex ("assets/style/classic/door.png");
+       auto dtex = game::engine.getSystem<RenderSystem>()->loadTexture("assets/style/classic/door.png");
        sprite->addSpriteSegment(SpriteData(dtex), 0);
 
-       auto dim = sprite->getSpriteSize();
+       auto dim = HLINES(sprite->getSpriteSize());
        door.assign<Solid>(dim.x, dim.y);
 }