-119
+32
97
100
1073742049
#include <entityx/entityx.h>
#include <common.hpp>
+#include <texture.hpp>
/**
* @struct Position
* @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) {}
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 */
};
struct SpriteData {
-
- SpriteData(uint64_t sid = 0, vec2 offset = 0.0f, vec2 size = 0.0f):
- sheetID(sid), offset(offset), size(size) {}
-
- uint64_t sheetID;
+
+ SpriteData(std::string path, vec2 offset):
+ offset(offset) {
+ pic = Texture::loadTexture(path);
+ size = Texture::imageDim(path);
+ }
+
+ GLuint pic;
vec2 offset;
vec2 size;
};
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
};
+class PhysicsSystem : public entityx::System<PhysicsSystem> {
+private:
+public:
+ void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt);
+};
class RenderSystem : public entityx::System<RenderSystem> {
private:
public:
void initColorIndex();
vec2 getIndex(Color c);
- dim2 imageDim(std::string fileName);
+ vec2 imageDim(std::string fileName);
}
class SpriteLoader {
return textures[index].second;
}
- const dim2 getTextureDim(void) {
+ const vec2 getTextureDim(void) {
return Texture::imageDim((*position).second);
}
};
void main(){
vec4 pixelColor = texture2D(sampler, vec2(texCoord.x, texCoord.y));
- gl_FragColor = pixelColor * color;
+ //TODO
+ if (pixelColor.w != 1.0f)
+ discard;
+ gl_FragColor = pixelColor * color;
}
});
}
+void PhysicsSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
+{
+ (void)ev;
+ en.each<Direction, Physics>([dt](entityx::Entity entity, Direction &direction, Physics &physics) {
+ (void)entity;
+ // TODO GET GRAVITY FROM WOLRD
+ direction.y += physics.g * dt;
+ });
+}
+
void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
{
(void)ev;
float flashAmt = 1-(hitDuration/maxHitDuration);
glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, flashAmt, flashAmt, 1.0);
}*/
- glBindTexture(GL_TEXTURE_2D, game::sprite_l.getSprite(S.first.sheetID));
+ glBindTexture(GL_TEXTURE_2D, S.first.pic);
glUniform1i(Render::worldShader.uniform[WU_texture], 0);
Render::worldShader.enable();
systems.add<InventorySystem>();
systems.add<WorldSystem>();
systems.add<PlayerSystem>();
+ systems.add<PhysicsSystem>();
systems.add<MovementSystem>();
systems.configure();
void Engine::update(entityx::TimeDelta dt)
{
systems.update<InputSystem>(dt);
+ //systems.update<PhysicsSystem>(dt);
systems.update<MovementSystem>(dt);
systems.update<WorldSystem>(dt);
systems.update<PlayerSystem>(dt);
e = game::entities.create();
e.assign<Position>(0.0f, 100.0f);
e.assign<Direction>(-0.01f, 0.0f);
+ e.assign<Physics>(-0.001f);
e.assign<Visible>(-.2f);
auto sprite_h = e.assign<Sprite>();
- sprite_h->addSpriteSegment(SpriteData(game::sprite_l.loadSprite("assets/cat.png"),
- vec2(0, 0),
- vec2(19, 15)),
+ sprite_h->addSpriteSegment(SpriteData("assets/cat.png",
+ vec2(0, 0)),
vec2(0, 0));
game::engine.getSystem<PlayerSystem>()->setPlayer(e);
return object;
}
- dim2 imageDim(std::string fileName) {
+ vec2 imageDim(std::string fileName) {
for(auto &t : LoadedTexture) {
if (t.name == fileName)
- return t.dim;
+ return vec2(t.dim.x, t.dim.y);
}
- return {0,0};
+ return vec2(0,0);
}
void freeTextures(void) {
static GLuint box_side = Texture::loadTexture("assets/ui/button_side_borders.png");
// the dimensions of the corner textures
- static dim2 box_corner_dim_t = Texture::imageDim("assets/ui/button_corners.png");
+ static vec2 box_corner_dim_t = Texture::imageDim("assets/ui/button_corners.png");
static vec2 box_corner_dim = vec2(box_corner_dim_t.x / 2.0, box_corner_dim_t.y / 2.0);
// the amount of bytes to skip in the OpenGL arrays (see below)
} else if (tname == "Sprite") {
auto sprite = entity.assign<Sprite>();
auto tex = abcd->Attribute("image");
- auto dim = Texture::imageDim(tex);
- sprite->addSpriteSegment(SpriteData(game::sprite_l.loadSprite(tex),
- vec2(0, 0),
- vec2(dim.x, dim.y) * 2),
+ sprite->addSpriteSegment(SpriteData(tex,
+ vec2(0, 0)),
vec2(0, 0));
}
std::vector<vec2> bg_tex;
bgTex++;
- dim2 mountainDim = bgTex.getTextureDim();
+ vec2 mountainDim = bgTex.getTextureDim();
auto xcoord = width / 2 * -1 + offset.x * 0.85f;
for (int i = 0; i <= width / mountainDim.x; i++) {
bg_items.emplace_back(mountainDim.x * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f);