diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-10-28 09:19:40 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-10-28 09:19:40 -0400 |
commit | e51b9ee1e0f9b8aeef98b8875f66260db0e7b502 (patch) | |
tree | 8f32a3de7032b97bddd0c34377f9f6988c1ab336 /src/world.cpp | |
parent | ed10ef9ede3d397672239c3b3dbe42cc6fbe56b4 (diff) | |
parent | 0a8654a125fad2961039e614fd10f1f683c0001f (diff) |
npc dialog
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/world.cpp b/src/world.cpp index 0b0defc..8f67d8b 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -363,6 +363,8 @@ void WorldSystem::load(const std::string& file) entity.assign<Name>(coalesce(wxml->Attribute("name"), abcd->Attribute("value"))); } else if (tname == "Dialog") { entity.assign<Dialog>(); + } else if (tname == "Grounded") { + entity.assign<Grounded>(); } abcd = abcd->NextSiblingElement(); @@ -1006,6 +1008,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; |