diff options
-rw-r--r-- | include/components.hpp | 21 | ||||
-rw-r--r-- | include/components/all.hpp | 6 | ||||
-rw-r--r-- | include/components/base.hpp | 29 | ||||
-rw-r--r-- | include/components/damage.hpp | 22 | ||||
-rw-r--r-- | include/particle.hpp | 9 | ||||
-rw-r--r-- | include/vector2.hpp | 5 | ||||
-rw-r--r-- | main.cpp | 2 | ||||
-rw-r--r-- | src/attack.cpp | 9 | ||||
-rw-r--r-- | src/components.cpp | 2 | ||||
-rw-r--r-- | src/inventory.cpp | 37 | ||||
-rw-r--r-- | src/particle.cpp | 8 | ||||
-rw-r--r-- | src/world.cpp | 4 |
12 files changed, 118 insertions, 36 deletions
diff --git a/include/components.hpp b/include/components.hpp index 2215a64..3f06867 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -22,25 +22,8 @@ #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 index 0000000..ecba09f --- /dev/null +++ b/include/components/all.hpp @@ -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 index 0000000..9139a75 --- /dev/null +++ b/include/components/base.hpp @@ -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 index 0000000..c257426 --- /dev/null +++ b/include/components/damage.hpp @@ -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_ diff --git a/include/particle.hpp b/include/particle.hpp index f49e055..822ac41 100644 --- a/include/particle.hpp +++ b/include/particle.hpp @@ -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 { diff --git a/include/vector2.hpp b/include/vector2.hpp index 828654c..5671ccd 100644 --- a/include/vector2.hpp +++ b/include/vector2.hpp @@ -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); @@ -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; diff --git a/src/attack.cpp b/src/attack.cpp index 226fe2f..525b0c3 100644 --- a/src/attack.cpp +++ b/src/attack.cpp @@ -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); } } ); diff --git a/src/components.cpp b/src/components.cpp index a711f45..af746ab 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -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(); } diff --git a/src/inventory.cpp b/src/inventory.cpp index 3995e3a..d669c00 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -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(); } diff --git a/src/particle.cpp b/src/particle.cpp index 52d0b23..02f3640 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -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 diff --git a/src/world.cpp b/src/world.cpp index f4be288..9a47576 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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); } |