From d7884127950260dd0f1b24aee0bfe64d847f990c Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 24 Oct 2016 07:55:41 -0400 Subject: [PATCH] Better sprites --- assets/cat.png | Bin 402 -> 557 bytes config/controls.dat | 2 +- include/components.hpp | 21 ++++++++++++++++----- include/texture.hpp | 4 ++-- shaders/new.frag | 5 ++++- src/components.cpp | 12 +++++++++++- src/engine.cpp | 2 ++ src/entities.cpp | 6 +++--- src/texture.cpp | 6 +++--- src/ui.cpp | 2 +- src/world.cpp | 8 +++----- 11 files changed, 46 insertions(+), 22 deletions(-) diff --git a/assets/cat.png b/assets/cat.png index c5b83c7faae25a94b8dcfaa0d496ab7b81054068..a5a09ce8951b9e3a506b20f0d8b826d47f1bae5f 100644 GIT binary patch delta 481 zcmV<70UrL61FZxhiBL{Q4GJ0x0000DNk~Le0000?0000y2nGNE0L-;q>X9Ka2?`Vq z4GU%eUEPseD}MozNklb>!3`MP?X9(a-UOM_5@!T~h=;gZS96o@@ph3=1 zbv9#|U`Zzo^8PBB5s9f+Zv)QyZw)X3!XRv0yl?GUT0QA$ z(o;SUhfq)R)~CaeB!uPmum#Vm&NW;n*tM<6lcMX>VSh*x!ct?&UuK^0bv(`nf38>4 z0^g^Tw&rRsdNkzz=`bV-Vd-+1%d-|dY84A-M>-5i0tgE`OGbNE^x03Y@6B!2dUP0) zgs|Kmra@}_e7UU7Z+AP>{OGfvwtqSdNkZ6bdDx?&d63nktn=wGBne@uP#WdGqo#40 zt7Pud=6`Fs?cUJ-LC|4H62fxjF!}z;dSB)B9P9U*XGVMEFbs4Ul7z6tIZS(F+V}lz z{A0g2<(RGCN_g+rq^HUKPt!yWLy{1dIEO_Sl%BQq9sAZftm`^D3`s)R6X&pK&(U(5 zHTT`S9vy}xAuM+e)9%NjJwjp}$JKFb{pfmh7%Gy4u-rN9X2R`5`rlXMhz>)N5SA8y X7t@zDw|~x^00000NkvXXu0mjfK^*3# delta 325 zcmV-L0lNOJ1d;2)moI!&7vG)=P(?fG)q^dtw?5bbwex58|1 z`Vg|Orw`D6UDqpY9LEhXLiMcy;4}=lFU!YXlH%UO$ylCEj0aggr!oEve2w}8{~Mos XD2v&Y4Gz4a00000NkvXXu0mjf*&v1| 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 #include +#include /** * @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 { +private: +public: + void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt); +}; class RenderSystem : public entityx::System { 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([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(); systems.add(); systems.add(); + systems.add(); systems.add(); systems.configure(); @@ -44,6 +45,7 @@ void Engine::render(entityx::TimeDelta dt) void Engine::update(entityx::TimeDelta dt) { systems.update(dt); + //systems.update(dt); systems.update(dt); systems.update(dt); systems.update(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(0.0f, 100.0f); e.assign(-0.01f, 0.0f); + e.assign(-0.001f); e.assign(-.2f); auto sprite_h = e.assign(); - 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()->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(); 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 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); -- 2.39.5