From 8a5ebb5b1c80e7ac857614cee7e7dbd9ab565429 Mon Sep 17 00:00:00 2001
From: Clyne Sullivan <tullivan99@gmail.com>
Date: Sat, 21 Oct 2017 10:08:41 -0400
Subject: z standardization

---
 include/inventory.hpp  |  1 -
 include/render.hpp     | 16 ++++++++++++++
 include/ui_quest.hpp   | 10 +++++----
 src/attack.cpp         |  3 ++-
 src/inventory.cpp      | 42 ++++++++++++++++++-----------------
 src/particle.cpp       | 14 +++++++-----
 src/player.cpp         |  7 ++++--
 src/render.cpp         | 13 ++++++-----
 src/systems/render.cpp | 29 +++++++++++++------------
 src/ui.cpp             | 41 +++++++++++++++++++----------------
 src/ui_menu.cpp        | 12 +++++-----
 src/world.cpp          | 59 ++++++++++++++++++++++++++------------------------
 12 files changed, 141 insertions(+), 106 deletions(-)

diff --git a/include/inventory.hpp b/include/inventory.hpp
index 273241a..753d90f 100644
--- a/include/inventory.hpp
+++ b/include/inventory.hpp
@@ -76,7 +76,6 @@ private:
 	constexpr static const char* itemsPath = "config/items.xml";
 	constexpr static int entrySize = 70;
 	constexpr static int hotbarSize = 4;
-	constexpr static float inventoryZ = -5.0f;
 	constexpr static unsigned int rowSize = 8;
 
 	static std::unordered_map<std::string, Item> itemList;
diff --git a/include/render.hpp b/include/render.hpp
index a21fcdd..e081b9d 100644
--- a/include/render.hpp
+++ b/include/render.hpp
@@ -66,6 +66,22 @@ typedef enum {
 } WorldUniform;
 
 namespace Render {
+	namespace ZRange {
+		constexpr float World     =  9.9f;
+		constexpr float RenderSys =  5.0f;
+		constexpr float Ground    = -4.5f;
+		constexpr float Attack    = -5.0f;
+		constexpr float Particle  = -8.0f;
+		constexpr float Important = -8.5f;
+		constexpr float Inventory = -9.0f;
+		constexpr float Dialog    = -9.3f;
+		constexpr float Quest     = -9.5f;
+		constexpr float Fade      = -9.7f;
+		constexpr float Menu      = -9.8f;
+		constexpr float Mouse     = -9.89f;
+		constexpr float Debug     = -9.9f;
+	}
+
     extern Shader worldShader;
     extern Shader textShader;
 
diff --git a/include/ui_quest.hpp b/include/ui_quest.hpp
index e06570a..1c478ca 100644
--- a/include/ui_quest.hpp
+++ b/include/ui_quest.hpp
@@ -30,12 +30,13 @@ namespace ui {
 		void draw(void) {
 			if (!_toggle)
 				return;
-			
+
+			float z = Render::ZRange::Quest;
 			float top_y = offset.y + 200;
-			ui::drawNiceBox(vec2 {offset.x - 200, top_y },
-			                vec2 {offset.x + 200, offset.y - 200 },
-			                -0.7f);
+			ui::drawNiceBox(vec2 {offset.x - 200, top_y }, vec2 {offset.x + 200, offset.y - 200 },
+				z);
 
+			FontSystem::setFontZ(z - 0.01f);
 			UISystem::putStringCentered(vec2(offset.x, top_y - 40), "Current Quests:");
 			
 			const auto& titles = QuestSystem::getQuestTitles();
@@ -47,6 +48,7 @@ namespace ui {
 				//ui::putText(x + 40, y, q.desc.c_str());
 				//y -= 40; 
 			}
+			FontSystem::setFontZ();
 		}
 	}
 }
diff --git a/src/attack.cpp b/src/attack.cpp
index 8c5d44a..cf2f627 100644
--- a/src/attack.cpp
+++ b/src/attack.cpp
@@ -132,7 +132,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
 #define RATE 3
 void AttackSystem::render(void)
 {
-	float z = -9.9f;
+	float z = Render::ZRange::Attack;
 	Render::worldShader.use();
 	Render::worldShader.enable();
 	for (auto& ae : effects) {
@@ -150,6 +150,7 @@ void AttackSystem::render(void)
 		glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts);
 		glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts + 3);
 		glDrawArrays(GL_TRIANGLES, 0, 6);
+		z -= 0.05f;
 	}
 	Render::worldShader.disable();
 	Render::worldShader.unuse();
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 947c7fc..1db8845 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -103,6 +103,7 @@ void InventorySystem::update(entityx::EntityManager &en, entityx::EventManager &
 
 void InventorySystem::render(void)
 {
+	float inventoryZ = Render::ZRange::Inventory;
 	int size = items.size();
 
 	// calculate positions
@@ -141,12 +142,12 @@ void InventorySystem::render(void)
 		glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, .6);
 		vec2 end = i.loc + entrySize - 6;
 		GLfloat coords[] = {
-			i.loc.x, i.loc.y, inventoryZ - 0.1, 0, 0,
-			end.x,   i.loc.y, inventoryZ - 0.1, 0, 0,
-			end.x,   end.y,   inventoryZ - 0.1, 0, 0,
-			end.x,   end.y,   inventoryZ - 0.1, 0, 0,
-			i.loc.x, end.y,   inventoryZ - 0.1, 0, 0,
-			i.loc.x, i.loc.y, inventoryZ - 0.1, 0, 0,
+			i.loc.x, i.loc.y, inventoryZ - 0.1f, 0, 0,
+			end.x,   i.loc.y, inventoryZ - 0.1f, 0, 0,
+			end.x,   end.y,   inventoryZ - 0.1f, 0, 0,
+			end.x,   end.y,   inventoryZ - 0.1f, 0, 0,
+			i.loc.x, end.y,   inventoryZ - 0.1f, 0, 0,
+			i.loc.x, i.loc.y, inventoryZ - 0.1f, 0, 0,
 		};
 
 		glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), coords);
@@ -170,12 +171,12 @@ void InventorySystem::render(void)
 			vec2 end = (n == movingItem) ? ui::mouse + truDim / 2 : loc + truDim;
 
 			GLfloat coords[] = {
-				sta.x, sta.y, inventoryZ - 0.2, 0, 1,
-				end.x, sta.y, inventoryZ - 0.2, 1, 1,
-				end.x, end.y, inventoryZ - 0.2, 1, 0,
-				end.x, end.y, inventoryZ - 0.2, 1, 0,
-				sta.x, end.y, inventoryZ - 0.2, 0, 0,
-				sta.x, sta.y, inventoryZ - 0.2, 0, 1,
+				sta.x, sta.y, inventoryZ - 0.2f, 0, 1,
+				end.x, sta.y, inventoryZ - 0.2f, 1, 1,
+				end.x, end.y, inventoryZ - 0.2f, 1, 0,
+				end.x, end.y, inventoryZ - 0.2f, 1, 0,
+				sta.x, end.y, inventoryZ - 0.2f, 0, 0,
+				sta.x, sta.y, inventoryZ - 0.2f, 0, 1,
 			};
 
 			glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), coords);
@@ -183,9 +184,9 @@ void InventorySystem::render(void)
 			if (n == movingItem)
 				glUniform4f(Render::textShader.uniform[WU_tex_color], .8, .8, 1, .8);
 			glDrawArrays(GL_TRIANGLES, 0, 6);
-			FontSystem::setFontZ(inventoryZ - 0.3); // TODO fix z's
+			FontSystem::setFontZ(inventoryZ - 0.3f);
 			UISystem::putString(i.loc, std::to_string(i.count));
-			FontSystem::setFontZ(-6);
+			FontSystem::setFontZ();
 			glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1);
 		}
 	}
@@ -201,13 +202,14 @@ void InventorySystem::render(void)
 		vec2 sta (pos.x, pos.y);
 		sta += i.item->drawOffset;
 		vec2 end (sta + (i.item->sprite.getDim() * game::HLINE));
+		float z = Render::ZRange::Attack + 0.1f;
 		GLfloat coords[] = {
-			sta.x, sta.y, -8, 0, 1,
-			end.x, sta.y, -8, 1, 1,
-			end.x, end.y, -8, 1, 0,
-			end.x, end.y, -8, 1, 0,
-			sta.x, end.y, -8, 0, 0,
-			sta.x, sta.y, -8, 0, 1,
+			sta.x, sta.y, z, 0, 1,
+			end.x, sta.y, z, 1, 1,
+			end.x, end.y, z, 1, 0,
+			end.x, end.y, z, 1, 0,
+			sta.x, end.y, z, 0, 0,
+			sta.x, sta.y, z, 0, 1,
 		};
 
 		glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), coords);
diff --git a/src/particle.cpp b/src/particle.cpp
index 3303027..d1a07a3 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -59,20 +59,22 @@ void ParticleSystem::render(void)
 	auto vbobuf = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
 	UserAssert(vbobuf != nullptr, "Failed to map the particle VBO");
 
+	float z = Render::ZRange::Particle;
 	for (unsigned int i = 0, offset = 0; i < parts.size(); i++, offset += entrySize) {
 		const auto& p = parts[i];
 		static const auto& hl = game::HLINE;
 		GLfloat coords[30] = {
-			p.location.x,      p.location.y,      -1, p.color.x, p.color.y,
-			p.location.x,      p.location.y + hl, -1, p.color.x, p.color.y,
-			p.location.x + hl, p.location.y + hl, -1, p.color.x, p.color.y,
-			p.location.x + hl, p.location.y + hl, -1, p.color.x, p.color.y,
-			p.location.x + hl, p.location.y,      -1, p.color.x, p.color.y,
-			p.location.x,      p.location.y,      -1, p.color.x, p.color.y
+			p.location.x,      p.location.y,      z, p.color.x, p.color.y,
+			p.location.x,      p.location.y + hl, z, p.color.x, p.color.y,
+			p.location.x + hl, p.location.y + hl, z, p.color.x, p.color.y,
+			p.location.x + hl, p.location.y + hl, z, p.color.x, p.color.y,
+			p.location.x + hl, p.location.y,      z, p.color.x, p.color.y,
+			p.location.x,      p.location.y,      z, p.color.x, p.color.y
 		};
 
 		//glBufferSubData(GL_ARRAY_BUFFER, offset, entrySize, coords);
 		std::memcpy(reinterpret_cast<void*>(reinterpret_cast<unsigned long long>(vbobuf) + offset), coords, entrySize);
+		z -= 0.0001;
 	}
 
 	UserAssert(glUnmapBuffer(GL_ARRAY_BUFFER) == GL_TRUE, "Failed to unmap the particle VBO");
diff --git a/src/player.cpp b/src/player.cpp
index db34347..07cb1a0 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -253,8 +253,11 @@ bool PlayerSystem::receive(const UseItemEvent& uie)
 					e.component<Hit>()->effect = uie.attack->effect;
 			}
 		} else if (uie.item->type == "Food") {
-			player.component<Health>()->health = player.component<Health>()->maxHealth;
-			InventorySystem::take(uie.item->name, 1);
+			auto health = player.component<Health>();
+			if (health->health < health->maxHealth) {
+				health->health = health->maxHealth;
+				InventorySystem::take(uie.item->name, 1);
+			}
 		}
 
 		cool.store(false);
diff --git a/src/render.cpp b/src/render.cpp
index b9a9770..85384ce 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -177,25 +177,26 @@ void render(const int& fps)
 	preRender();
 
 	WorldSystem::render();
-	ParticleSystem::render();
-	AttackSystem::render();
 	RenderSystem::render();
+	AttackSystem::render();
+	ParticleSystem::render();
+	UISystem::render();
 	InventorySystem::render();
+	ui::draw();
+	FontSystem::render();
 
 	// draw the debug overlay if desired
 	if (ui::debug) {
 		auto pos = PlayerSystem::getPosition();
+		FontSystem::setFontZ(Render::ZRange::Debug);
 		UISystem::putText(vec2(offset.x - game::SCREEN_WIDTH / 2, (offset.y + game::SCREEN_HEIGHT / 2) - FontSystem::getSize()),
 		    "loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s\nmem: %llukb (%d)",
 			pos.toString(2).c_str(), offset.toString(2).c_str(), fps,
 			game::time::getTickCount(), ParticleSystem::getCount(),
 			WorldSystem::getXMLFile().c_str(), getUsedMem() / 1024, balance
 			);
+		FontSystem::setFontZ();
 	}
-
-	UISystem::render();
-	ui::draw();
-	FontSystem::render();
 	
 	WindowSystem::render();
 }
diff --git a/src/systems/render.cpp b/src/systems/render.cpp
index f72832b..48cf18c 100644
--- a/src/systems/render.cpp
+++ b/src/systems/render.cpp
@@ -109,7 +109,7 @@ void RenderSystem::render(void)
 				}
 			}
 
-			its-=.01;
+			its -= 0.01f;
 		}
 		glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
 
@@ -118,13 +118,14 @@ void RenderSystem::render(void)
 			auto& health = *entity.component<Health>();
 			width *= health.health / static_cast<float>(health.maxHealth);
 
+			float Z = Render::ZRange::Ground - 0.3f;
 			GLfloat health_coord[] = {
-				pos.x, pos.y, -9, 0, 0,
-				pos.x + width, pos.y, -9, 0, 0,
-				pos.x + width, pos.y - 5, -9, 0, 0,
-				pos.x + width, pos.y - 5, -9, 0, 0,
-				pos.x, pos.y - 5, -9, 0, 0,
-				pos.x, pos.y, -9, 0, 0,
+				pos.x, pos.y, Z, 0, 0,
+				pos.x + width, pos.y, Z, 0, 0,
+				pos.x + width, pos.y - 5, Z, 0, 0,
+				pos.x + width, pos.y - 5, Z, 0, 0,
+				pos.x, pos.y - 5, Z, 0, 0,
+				pos.x, pos.y, Z, 0, 0,
 			};
 
 			Colors::red.use();
@@ -132,17 +133,17 @@ void RenderSystem::render(void)
 			glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), health_coord + 3);
 			glDrawArrays(GL_TRIANGLES, 0, 6);
 		}
+
+		if (entity.has_component<Name>()) {
+			FontSystem::setFontZ(Render::ZRange::Ground - 0.3f);
+			UISystem::putStringCentered(vec2(pos.x + entity.component<Solid>()->width / 2,
+				pos.y - FontSystem::getSize() - HLINES(0.5)), entity.component<Name>()->name);
+		}
 	});
 
+	FontSystem::setFontZ();
 	Render::worldShader.disable();
 	Render::worldShader.unuse();
-
-	game::entities.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) {
-		(void)e;
-		(void)v;
-		FontSystem::setFontZ(-5.0f);
-		UISystem::putStringCentered(vec2(pos.x + dim.width / 2, pos.y - FontSystem::getSize() - HLINES(0.5)), name.name);
-	});
 }
 
 void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
diff --git a/src/ui.cpp b/src/ui.cpp
index 8a2d64d..a1cd2d5 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -342,14 +342,14 @@ namespace ui {
 		quest::draw();
 
 		if (pageTexReady) {
-
+			float z = Render::ZRange::Important;
             GLfloat page_verts[] = {
-				offset.x - 300, SCREEN_HEIGHT - 100, -6.0, 0, 0,
-				offset.x + 300, SCREEN_HEIGHT - 100, -6.0, 1, 0,
-				offset.x + 300, SCREEN_HEIGHT - 600, -6.0, 1, 1,
-				offset.x + 300, SCREEN_HEIGHT - 600, -6.0, 1, 1,
-				offset.x - 300, SCREEN_HEIGHT - 600, -6.0, 0, 1,
-				offset.x - 300, SCREEN_HEIGHT - 100, -6.0, 0, 0,
+				offset.x - 300, SCREEN_HEIGHT - 100, z, 0, 0,
+				offset.x + 300, SCREEN_HEIGHT - 100, z, 1, 0,
+				offset.x + 300, SCREEN_HEIGHT - 600, z, 1, 1,
+				offset.x + 300, SCREEN_HEIGHT - 600, z, 1, 1,
+				offset.x - 300, SCREEN_HEIGHT - 600, z, 0, 1,
+				offset.x - 300, SCREEN_HEIGHT - 100, z, 0, 0,
 			};
 
             glActiveTexture(GL_TEXTURE0);
@@ -375,7 +375,7 @@ namespace ui {
 		glActiveTexture(GL_TEXTURE0);
 		mouseTex.use();
 		Render::useShader(&Render::textShader);
-		Render::drawRect(vec2(ui::mouse.x, ui::mouse.y - 64), vec2(ui::mouse.x + 64, ui::mouse.y), -9.9);
+		Render::drawRect(vec2(ui::mouse.x, ui::mouse.y - 64), vec2(ui::mouse.x + 64, ui::mouse.y), Render::ZRange::Mouse);
 		Render::textShader.unuse();
 	}
 
@@ -758,13 +758,14 @@ void UISystem::render(void)
 		vec2 p1 (offset.x - game::SCREEN_WIDTH / 2, offset.y - game::SCREEN_HEIGHT / 2);
 		vec2 p2 (p1.x + game::SCREEN_WIDTH, p1.y + game::SCREEN_HEIGHT);
 
+		float z = Render::ZRange::Fade;
 		GLfloat backdrop[] = {
-			p1.x, p1.y, -7.9, 0, 0,
-			p2.x, p1.y, -7.9, 0, 0, 
-			p2.x, p2.y, -7.9, 0, 0,
-			p2.x, p2.y, -7.9, 0, 0,
-			p1.x, p2.y, -7.9, 0, 0,
-			p1.x, p1.y, -7.9, 0, 0,
+			p1.x, p1.y, z, 0, 0,
+			p2.x, p1.y, z, 0, 0, 
+			p2.x, p2.y, z, 0, 0,
+			p2.x, p2.y, z, 0, 0,
+			p1.x, p2.y, z, 0, 0,
+			p1.x, p1.y, z, 0, 0,
 		};
 
 		Render::textShader.use();
@@ -778,13 +779,14 @@ void UISystem::render(void)
 
 		Render::textShader.disable();
 		Render::textShader.unuse();
-		//setFontZ(-8.0);
 	}
 
 	if (!dialogText.empty()) {
+		float z = Render::ZRange::Dialog;
 		vec2 where (offset.x - 300, game::SCREEN_HEIGHT - 60);
-		ui::drawNiceBox(vec2(where.x - 10, where.y - 200), vec2(where.x + 620, where.y + 20), -5.5f);
-		FontSystem::setFontZ(-6.0f);
+		ui::drawNiceBox(vec2(where.x - 10, where.y - 200), vec2(where.x + 620, where.y + 20),
+			z);
+		FontSystem::setFontZ(z - 0.1f);
 		putString(where, ui::typeOut(dialogText), where.x + 600);
 
 		if (!dialogOptions.empty()) {
@@ -807,9 +809,10 @@ void UISystem::render(void)
 
 	if (!importantText.empty()) {
 		FontSystem::setFontSize(FontSystem::SizeLarge);
-		FontSystem::setFontZ(-9.0f);
+		FontSystem::setFontZ(Render::ZRange::Fade - 0.05f);
 		putStringCentered(vec2(offset.x, 400), ui::typeOut(importantText));
-		FontSystem::setFontZ(-6.0f);
 		FontSystem::setFontSize(FontSystem::SizeSmall);
 	}
+
+	FontSystem::setFontZ();
 }
diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp
index f0b2eeb..920166d 100644
--- a/src/ui_menu.cpp
+++ b/src/ui_menu.cpp
@@ -248,6 +248,8 @@ namespace ui {
 		}
 
         void draw(void) {
+			float z = Render::ZRange::Menu;
+
 			if (currentMenu == nullptr)
 				return;
 
@@ -258,7 +260,7 @@ namespace ui {
 
             game::config::update();
             FontSystem::setFontSize(FontSystem::SizeLarge);
-			FontSystem::setFontZ(-9.0);
+			FontSystem::setFontZ(z - 0.03f);
 	
             mouse.x = ui::premouse.x+offset.x-(SCREEN_WIDTH/2);
             mouse.y = (offset.y+SCREEN_HEIGHT/2)-ui::premouse.y;
@@ -272,7 +274,7 @@ namespace ui {
 
 			back.use();
 			Render::drawRect(vec2(offset.x - SCREEN_WIDTH / 2 - 1, offset.y - (SCREEN_HEIGHT / 2)),
-			                 vec2(offset.x + SCREEN_WIDTH / 2, offset.y + (SCREEN_HEIGHT / 2)), -8.5);
+			    vec2(offset.x + SCREEN_WIDTH / 2, offset.y + (SCREEN_HEIGHT / 2)), z);
 
 			Render::textShader.unuse();
 
@@ -309,7 +311,7 @@ namespace ui {
                         }
                     }
 
-					ui::drawNiceBoxColor(loc, end, -8.6, Color(cMult, cMult, cMult, 1.0f));
+					ui::drawNiceBoxColor(loc, end, z - 0.01f, Color(cMult, cMult, cMult, 1.0f));
                     //draw the button text
                     UISystem::putStringCentered(vec2(loc.x + (m.dim.x / 2),
                     	loc.y + (m.dim.y / 2) - (FontSystem::getSize() / 2)),
@@ -334,7 +336,7 @@ namespace ui {
                         m.slider.sliderLoc *= m.dim.x - sliderW;
                     }
 
-					ui::drawNiceBoxColor(loc, end, -8.6, Color(.5f, .5f, .5f, 1.0f));
+					ui::drawNiceBoxColor(loc, end, z - 0.02f, Color(.5f, .5f, .5f, 1.0f));
 
                     //test if mouse is inside of the slider's borders
                     if ((mouse.x >= loc.x && mouse.x <= end.x) && (mouse.y >= loc.y && mouse.y <= end.y)) {
@@ -375,7 +377,7 @@ namespace ui {
 
 			SDLReceiver::clicked = false;
             FontSystem::setFontSize(FontSystem::SizeSmall);
-			FontSystem::setFontZ(-8.0);
+			FontSystem::setFontZ();
         }
 
 
diff --git a/src/world.cpp b/src/world.cpp
index dcbc707..b163979 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -430,6 +430,8 @@ void WorldSystem::die(void)
 
 void WorldSystem::render(void)
 {
+	float z = Render::ZRange::World;
+
 	static Color ambient;
 
 	const auto SCREEN_WIDTH = game::SCREEN_WIDTH;
@@ -475,12 +477,12 @@ void WorldSystem::render(void)
 		skyOffset++;
 
 	GLfloat skyverts[] = {
-		offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f, 0, skyOffset,
-		offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.9f, 1, skyOffset,
-		offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f, 1, skyOffset,
-		offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f, 1, skyOffset,
-		offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f, 0, skyOffset,
-		offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f, 0, skyOffset,
+		offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, z, 0, skyOffset,
+		offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, z, 1, skyOffset,
+		offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, z, 1, skyOffset,
+		offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, z, 1, skyOffset,
+		offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, z, 0, skyOffset,
+		offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, z, 0, skyOffset,
 	};
 
 	// rendering!!
@@ -510,12 +512,12 @@ void WorldSystem::render(void)
 
 		for (auto &s : stars) {
 			float data[30] = {
-				s.x + xcoord, s.y, 9.7, 0, 0,
-				s.x + xcoord + stardim, s.y, 9.7, 1, 0,
-				s.x + xcoord + stardim, s.y + stardim, 9.7, 1, 1,
-				s.x + xcoord + stardim, s.y + stardim, 9.7, 1, 1,
-				s.x + xcoord, s.y + stardim, 9.7, 0, 1,
-				s.x + xcoord, s.y, 9.7, 0, 0
+				s.x + xcoord, s.y, z - 0.1f, 0, 0,
+				s.x + xcoord + stardim, s.y, z - 0.1f, 1, 0,
+				s.x + xcoord + stardim, s.y + stardim, z - 0.1f, 1, 1,
+				s.x + xcoord + stardim, s.y + stardim, z - 0.1f, 1, 1,
+				s.x + xcoord, s.y + stardim, z - 0.1f, 0, 1,
+				s.x + xcoord, s.y, z - 0.1f, 0, 0
 			};
 
 			std::memcpy(si, data, sizeof(float) * 30);
@@ -538,7 +540,7 @@ void WorldSystem::render(void)
 	float parallax = 0.85f;
 	float parallaxChange = 0.75f / layerCount;
 
-	float z = 8.0f;
+	z -= 0.2f;
 	for (int i = 0; i < layerCount; i++, z -= 0.1f, parallax -= parallaxChange) {
 		bgTex++;
 		auto mountainDim = bgTex.getTextureDim() * game::HLINE;
@@ -578,12 +580,12 @@ void WorldSystem::render(void)
 		world.indoorTex.use();
 		auto dim = world.indoorTex.getDim() * game::HLINE;
 		GLfloat verts[] = {
-			world.startX,         GROUND_HEIGHT_MINIMUM,         z - 0.1f, 0, 0,
-			world.startX + dim.x, GROUND_HEIGHT_MINIMUM,         z - 0.1f, 1, 0,
-			world.startX + dim.x, GROUND_HEIGHT_MINIMUM + dim.y, z - 0.1f, 1, 1,
-			world.startX + dim.x, GROUND_HEIGHT_MINIMUM + dim.y, z - 0.1f, 1, 1,
-			world.startX,         GROUND_HEIGHT_MINIMUM + dim.y, z - 0.1f, 0, 1,
-			world.startX,         GROUND_HEIGHT_MINIMUM,         z - 0.1f, 0, 0,
+			world.startX,         GROUND_HEIGHT_MINIMUM,         z, 0, 0,
+			world.startX + dim.x, GROUND_HEIGHT_MINIMUM,         z, 1, 0,
+			world.startX + dim.x, GROUND_HEIGHT_MINIMUM + dim.y, z, 1, 1,
+			world.startX + dim.x, GROUND_HEIGHT_MINIMUM + dim.y, z, 1, 1,
+			world.startX,         GROUND_HEIGHT_MINIMUM + dim.y, z, 0, 1,
+			world.startX,         GROUND_HEIGHT_MINIMUM,         z, 0, 0,
 		};
 
 		glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts);
@@ -608,6 +610,7 @@ void WorldSystem::render(void)
 	waitToSwap = true;
 
 	bgTex++;
+	z = Render::ZRange::Ground;
 
 	static std::vector<GLfloat> dirt;
 	if (dirt.size() != world.data.size() * 30) {
@@ -626,7 +629,7 @@ void WorldSystem::render(void)
 
 		int ty = world.data[i].groundHeight / 64 + world.data[i].groundColor;
 		GLfloat five[5] = {
-			0, 0, world.startX + HLINES(i), world.data[i].groundHeight - GRASS_HEIGHT, -4
+			0, 0, world.startX + HLINES(i), world.data[i].groundHeight - GRASS_HEIGHT, z - 0.1f
 		};
 
 		push5(dirtp, five);
@@ -677,7 +680,7 @@ void WorldSystem::render(void)
 			// actually draw the grass.
 			if (wd.groundHeight) {
 				float five[5] = {
-					0, 1, world.startX + HLINES(i), wd.groundHeight + gh[0], -3
+					0, 1, world.startX + HLINES(i), wd.groundHeight + gh[0], z - 0.2f
 				};
 
 				push5(grassp, five);
@@ -724,12 +727,12 @@ void WorldSystem::render(void)
 			
 		auto yOffset = offset.y - static_cast<float>(SCREEN_HEIGHT) / 2.0f;
 		GLfloat blackBar[] = {
-			s,            yOffset,           -3.5f, 0.0f, 0.0f,
-			world.startX, yOffset,           -3.5f, 1.0f, 0.0f,
-			world.startX, yOffset + sheight, -3.5f, 1.0f, 1.0f,
-			world.startX, yOffset + sheight, -3.5f, 1.0f, 1.0f,
-   			s,            yOffset + sheight, -3.5f, 0.0f, 1.0f,
-			s,            yOffset,           -3.5f, 0.0f, 0.0f
+			s,            yOffset,           z - 0.3f, 0.0f, 0.0f,
+			world.startX, yOffset,           z - 0.3f, 1.0f, 0.0f,
+			world.startX, yOffset + sheight, z - 0.3f, 1.0f, 1.0f,
+			world.startX, yOffset + sheight, z - 0.3f, 1.0f, 1.0f,
+   			s,            yOffset + sheight, z - 0.3f, 0.0f, 1.0f,
+			s,            yOffset,           z - 0.3f, 0.0f, 0.0f
 		};
 
 		if (offset.x + world.startX > s) {
@@ -758,7 +761,7 @@ void WorldSystem::render(void)
 		Render::worldShader.use();
 		Colors::red.use();
 		vec2 ll = vec2 {world.startX, GROUND_HEIGHT_MINIMUM};
-		Render::drawRect(ll, ll + vec2(world.indoorTex.getDim().x, 4), -3);
+		Render::drawRect(ll, ll + vec2(world.indoorTex.getDim().x, 4), z - 1);
 		Render::worldShader.unuse();
 	}
 
-- 
cgit v1.2.3