aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--assets/cat.pngbin402 -> 557 bytes
-rw-r--r--config/controls.dat2
-rw-r--r--include/components.hpp21
-rw-r--r--include/texture.hpp4
-rw-r--r--shaders/new.frag5
-rw-r--r--src/components.cpp12
-rw-r--r--src/engine.cpp2
-rw-r--r--src/entities.cpp6
-rw-r--r--src/texture.cpp6
-rw-r--r--src/ui.cpp2
-rw-r--r--src/world.cpp8
11 files changed, 46 insertions, 22 deletions
diff --git a/assets/cat.png b/assets/cat.png
index c5b83c7..a5a09ce 100644
--- a/assets/cat.png
+++ b/assets/cat.png
Binary files differ
diff --git a/config/controls.dat b/config/controls.dat
index 679c014..c6b7131 100644
--- a/config/controls.dat
+++ b/config/controls.dat
@@ -1,4 +1,4 @@
-119
+32
97
100
1073742049
diff --git a/include/components.hpp b/include/components.hpp
index d2655c9..857236f 100644
--- a/include/components.hpp
+++ b/include/components.hpp
@@ -11,6 +11,7 @@
#include <entityx/entityx.h>
#include <common.hpp>
+#include <texture.hpp>
/**
* @struct Position
@@ -86,17 +87,22 @@ struct Solid {
* @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;
};
@@ -182,6 +188,11 @@ public:
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:
diff --git a/include/texture.hpp b/include/texture.hpp
index 88dae65..ad5211c 100644
--- a/include/texture.hpp
+++ b/include/texture.hpp
@@ -32,7 +32,7 @@ namespace Texture {
void initColorIndex();
vec2 getIndex(Color c);
- dim2 imageDim(std::string fileName);
+ vec2 imageDim(std::string fileName);
}
class SpriteLoader {
@@ -116,7 +116,7 @@ public:
return textures[index].second;
}
- const dim2 getTextureDim(void) {
+ const vec2 getTextureDim(void) {
return Texture::imageDim((*position).second);
}
};
diff --git a/shaders/new.frag b/shaders/new.frag
index fa8a260..3537e26 100644
--- a/shaders/new.frag
+++ b/shaders/new.frag
@@ -5,5 +5,8 @@ varying vec4 color;
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;
}
diff --git a/src/components.cpp b/src/components.cpp
index 32d0f79..45a9315 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -16,6 +16,16 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
});
}
+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;
@@ -61,7 +71,7 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &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();
diff --git a/src/engine.cpp b/src/engine.cpp
index a367e27..90cfb3a 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -25,6 +25,7 @@ void Engine::init(void) {
systems.add<InventorySystem>();
systems.add<WorldSystem>();
systems.add<PlayerSystem>();
+ systems.add<PhysicsSystem>();
systems.add<MovementSystem>();
systems.configure();
@@ -44,6 +45,7 @@ void Engine::render(entityx::TimeDelta dt)
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);
diff --git a/src/entities.cpp b/src/entities.cpp
index 1426eaf..29380c8 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -13,11 +13,11 @@ void entityxTest(void)
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);
diff --git a/src/texture.cpp b/src/texture.cpp
index bdac28e..1f80d38 100644
--- a/src/texture.cpp
+++ b/src/texture.cpp
@@ -144,12 +144,12 @@ namespace Texture{
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) {
diff --git a/src/ui.cpp b/src/ui.cpp
index 85b2d2b..43dd6cc 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -682,7 +682,7 @@ namespace ui {
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)
diff --git a/src/world.cpp b/src/world.cpp
index 78de9ed..e44406e 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -354,10 +354,8 @@ void WorldSystem::load(const std::string& file)
} 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));
}
@@ -752,7 +750,7 @@ void WorldSystem::render(void)
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);