diff options
-rw-r--r-- | include/components.hpp | 34 | ||||
-rw-r--r-- | include/events.hpp | 2 | ||||
-rw-r--r-- | src/player.cpp | 3 | ||||
-rw-r--r-- | src/window.cpp | 2 | ||||
-rw-r--r-- | src/world.cpp | 11 | ||||
-rw-r--r-- | xml/entities.xml | 3 |
6 files changed, 51 insertions, 4 deletions
diff --git a/include/components.hpp b/include/components.hpp index becc839..c0b7110 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -92,12 +92,16 @@ struct Solid { * @param w The desired width of the entity. * @param h The desired height of the entity. */ - Solid(float w = 0.0f, float h = 0.0f): width(w), height(h) {} - Solid(float w = 0.0f, float h = 0.0f, vec2 offset = 0.0f): width(w), height(h), offset(offset) {} + Solid(float w = 0.0f, float h = 0.0f): width(w), height(h) {offset = 0.0f; passable = true; } + //Solid(float w = 0.0f, float h = 0.0f, vec2 offset = 0.0f): width(w), height(h), offset(offset) {passable = true; } + + void Passable(bool v) {passable = v;} + bool Passable(void) {return passable;} float width; /**< The width of the entity in units */ float height; /**< The height of the entity in units */ vec2 offset; /**< This allows us to make the hitbox in any spot */ + bool passable; /**< This determines whether or not one can pass by the entity */ }; struct SpriteData { @@ -153,6 +157,32 @@ struct Sprite { return 0; } + vec2 getSpriteSize() { + vec2 st; /** the start location of the sprite */ + vec2 dim; /** how wide the sprite is */ + + if (sprite.size()) { + st.x = sprite[0].second.x; + st.y = sprite[0].second.y; + } else { + return vec2(0.0f, 0.0f); + } + + for (auto &s : sprite) { + if (s.second.x < st.x) + st.x = s.second.x; + if (s.second.y < st.y) + st.y = s.second.y; + + if (s.second.x + s.first.size.x > dim.x) + dim.x = s.second.x + s.first.size.x; + if (s.second.y + s.first.size.y > dim.y) + dim.y = s.second.y + s.first.size.y; + } + + return dim; + } + std::vector<std::pair<SpriteData, vec2>> sprite; bool faceLeft; }; diff --git a/include/events.hpp b/include/events.hpp index 5cd8040..d98d52a 100644 --- a/include/events.hpp +++ b/include/events.hpp @@ -48,7 +48,7 @@ struct BGMToggleEvent { }; struct WindowResizeEvent { - WindowResizeEvent(int w, int h) + WindowResizeEvent(int w = 640, int h = 480) : x(w), y(h) {} int x; diff --git a/src/player.cpp b/src/player.cpp index 8808a69..59274b3 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -19,6 +19,9 @@ void PlayerSystem::create(void) sprite->addSpriteSegment(SpriteData("assets/cat.png", vec2(0, 0)), vec2(0, 0)); + vec2 dim = player.component<Sprite>().get()->getSpriteSize(); + float cdat[2] = {dim.x, dim.y}; + player.assign<Solid>(cdat[0], cdat[1]); } void PlayerSystem::configure(entityx::EventManager &ev) diff --git a/src/window.cpp b/src/window.cpp index 69c383c..4c73b8b 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -71,9 +71,9 @@ void WindowSystem::configure(entityx::EventManager &ev) void WindowSystem::receive(const WindowResizeEvent &wre) { - game::SCREEN_WIDTH = wre.x; game::SCREEN_HEIGHT = wre.y; + glViewport(0, 0, wre.x, wre.y); SDL_SetWindowSize(window, wre.x, wre.y); } diff --git a/src/world.cpp b/src/world.cpp index d7639c2..365345d 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -359,6 +359,17 @@ void WorldSystem::load(const std::string& file) vec2(0, 0)); } else if (tname == "Portal") { entity.assign<Portal>(wxml->StrAttribute("inside")); + } else if (tname == "Solid") { + vec2 dim; + + if (abcd->Attribute("value") != nullptr) { + dim = str2coord(abcd->StrAttribute("value")); + } else { + dim = entity.component<Sprite>().get()->getSpriteSize(); + } + + float cdat[2] = {dim.x, dim.y}; + entity.assign<Solid>(cdat[0], cdat[1]); } abcd = abcd->NextSiblingElement(); diff --git a/xml/entities.xml b/xml/entities.xml index bcaa455..306085b 100644 --- a/xml/entities.xml +++ b/xml/entities.xml @@ -4,6 +4,7 @@ <Position value="0.0,100.0" /> <Visible value="0.2" /> <Sprite image="assets/NPC.png" /> + <Solid /> </npc> <structure> @@ -11,10 +12,12 @@ <Visible value="0.25" /> <Sprite image="assets/style/classic/house1.png" /> <Portal /> + <Solid /> </structure> <chest> <Position value="0.0,100.0" /> <Visible value="0.15" /> <Sprite image="assets/chest.png" /> + <Solid /> </chest> |