diff options
-rw-r--r-- | include/components.hpp | 11 | ||||
-rw-r--r-- | shaders/new.frag | 4 | ||||
-rw-r--r-- | src/components.cpp | 1 | ||||
-rw-r--r-- | src/engine.cpp | 1 | ||||
-rw-r--r-- | src/ui.cpp | 6 | ||||
-rw-r--r-- | src/world.cpp | 21 | ||||
-rw-r--r-- | xml/entities.xml | 2 |
7 files changed, 40 insertions, 6 deletions
diff --git a/include/components.hpp b/include/components.hpp index 1195337..507aa33 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -62,6 +62,16 @@ struct Physics { }; /** + * @struct Grounded + * @brief Places an entity without physics on the ground. + * This is used so we don't have to update the physics of a non-moving object every loop. + */ +struct Grounded { + //TODO possibly make a way to change this + bool grounded = false; +}; + +/** * @struct Health * @brief Gives and entity health and stuff. */ @@ -200,7 +210,6 @@ struct Animate { }; //TODO - struct Input { }; diff --git a/shaders/new.frag b/shaders/new.frag index 3537e26..0e4ed05 100644 --- a/shaders/new.frag +++ b/shaders/new.frag @@ -6,7 +6,7 @@ varying vec4 color; void main(){ vec4 pixelColor = texture2D(sampler, vec2(texCoord.x, texCoord.y)); //TODO - if (pixelColor.w != 1.0f) - discard; + //if (pixelColor.w != 1.0f) + // discard; gl_FragColor = pixelColor * color; } diff --git a/src/components.cpp b/src/components.cpp index e00d474..609b5f4 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -93,6 +93,7 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, en.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) { (void)e; (void)v; + ui::setFontZ(-5.0); ui::putStringCentered(pos.x + dim.width / 2, pos.y - ui::fontSize - HLINES(0.5), name.name); }); } diff --git a/src/engine.cpp b/src/engine.cpp index 04ea912..148c496 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -46,7 +46,6 @@ 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); @@ -238,7 +238,7 @@ namespace ui { void setFontSize(unsigned int size) { (void)size; - /*if (size == 16) { + if (size == 16) { if (!ft16loaded) { loadFontSize(fontSize = size, ftex16, ftdat16); ft16loaded = true; @@ -254,7 +254,7 @@ namespace ui { ftex = &ftex24; ftdat = &ftdat24; fontSize = 24; - }*/ + } } /* @@ -303,9 +303,11 @@ namespace ui { * Draw the character: */ + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,(*ftex)[c-33]); glUniform1i(Render::textShader.uniform[WU_texture], 0); + glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, 1.0f); //glDisable(GL_DEPTH_TEST); diff --git a/src/world.cpp b/src/world.cpp index 3ff819b..7c53ee4 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -400,6 +400,8 @@ void WorldSystem::load(const std::string& file) entity.assign<Physics>(g); } else if (tname == "Name") { entity.assign<Name>(coalesce(wxml->Attribute("name"), abcd->Attribute("value"))); + } else if (tname == "Grounded") { + entity.assign<Grounded>(); } abcd = abcd->NextSiblingElement(); @@ -1043,6 +1045,25 @@ void WorldSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, void WorldSystem::detect(entityx::TimeDelta dt) { + game::entities.each<Grounded, Position, Solid>( + [&](entityx::Entity e, Grounded &g, Position &loc, Solid &dim) { + (void)e; + if (!g.grounded) { + // get the line the entity is on + int line = std::clamp(static_cast<int>((loc.x + dim.width / 2 - world.startX) / game::HLINE), + 0, + static_cast<int>(world.data.size())); + + // make sure entity is above ground + const auto& data = world.data; + if (loc.y != data[line].groundHeight) { + loc.y = data[line].groundHeight; + e.remove<Grounded>(); + } + } + + }); + game::entities.each<Direction, Physics>( [&](entityx::Entity e, Direction &vel, Physics &phys) { (void)e; diff --git a/xml/entities.xml b/xml/entities.xml index 431c067..2bcd1bf 100644 --- a/xml/entities.xml +++ b/xml/entities.xml @@ -16,6 +16,7 @@ <Sprite image="assets/style/classic/house1.png" /> <Portal /> <Solid /> + <Grounded /> </structure> <chest> @@ -23,4 +24,5 @@ <Visible value="0.15" /> <Sprite image="assets/chest.png" /> <Solid /> + <Grounded /> </chest> |