From 0a8654a125fad2961039e614fd10f1f683c0001f Mon Sep 17 00:00:00 2001
From: Andy <drumsetmonkey@gmail.com>
Date: Fri, 28 Oct 2016 08:30:14 -0400
Subject: Text is fixed, and objects can be placed on the ground

---
 src/world.cpp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

(limited to 'src/world.cpp')

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;
-- 
cgit v1.2.3