* @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 {
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;
};
};
struct WindowResizeEvent {
- WindowResizeEvent(int w, int h)
+ WindowResizeEvent(int w = 640, int h = 480)
: x(w), y(h) {}
int x;
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)
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);
}
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();
<Position value="0.0,100.0" />
<Visible value="0.2" />
<Sprite image="assets/NPC.png" />
+ <Solid />
</npc>
<structure>
<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>