]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Better sprites
authorAndy <drumsetmonkey@gmail.com>
Mon, 24 Oct 2016 11:55:41 +0000 (07:55 -0400)
committerAndy <drumsetmonkey@gmail.com>
Mon, 24 Oct 2016 11:55:41 +0000 (07:55 -0400)
assets/cat.png
config/controls.dat
include/components.hpp
include/texture.hpp
shaders/new.frag
src/components.cpp
src/engine.cpp
src/entities.cpp
src/texture.cpp
src/ui.cpp
src/world.cpp

index c5b83c7faae25a94b8dcfaa0d496ab7b81054068..a5a09ce8951b9e3a506b20f0d8b826d47f1bae5f 100644 (file)
Binary files a/assets/cat.png and b/assets/cat.png differ
index 679c014997ea62f66b389359dde88a31cf906777..c6b7131df9331804bbc78852e58766a7ad80443c 100644 (file)
@@ -1,4 +1,4 @@
-119
+32
 97
 100
 1073742049
index d2655c985344b861aed379c67b05b7a79058aabb..857236f65d037a6ac8c03f52af51ae0195c0ef43 100644 (file)
@@ -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:
index 88dae654a6b3208fe9951620367a48689d8420a0..ad5211c5ef6b913e8c515a6d436d94fc2220979e 100644 (file)
@@ -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);
        }
 };
index fa8a260222eef42a38af7e078bf32510d67ffe52..3537e265045bd024d77e6831dd9dbdea5ec6562d 100644 (file)
@@ -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;
 }
index 32d0f7976db82b7cd9e4386afc740cb514b4a60f..45a931544bb724278fc3ffb9a7167126c1019a67 100644 (file)
@@ -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();
 
index a367e2777d5dd6086d275725a7fea0447d429259..90cfb3ac970cc3cf7b6f189cab0007ab45fa7c5f 100644 (file)
@@ -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);
index 1426eafdabf36fd2758e91922432bb45125805fa..29380c8f255ec9b1b78fb0ae95f9bc7e33997fac 100644 (file)
@@ -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);
index bdac28e07d09f3cc91142a71d03a5d0e7db73481..1f80d38fe58ef6058adce90732e41003deb2950d 100644 (file)
@@ -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) {
index 85b2d2b7015bfad79572c6febc464061d1f1467c..43dd6cc04b416b3a0f65743a8810d15137f8151b 100644 (file)
@@ -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)
index 78de9ed5b76f69ee92ef753013a7b0fcc9adc680..e44406ecb3f25a7d4e6830cc21dd598a56a7a183 100644 (file)
@@ -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);