浏览代码

place break blocks

meemknight 1 年之前
父节点
当前提交
8d034d737a

+ 150 - 51
Pika/gameplay/containers/isometricGame/isometricGameEditor.cpp

@@ -78,7 +78,7 @@ bool IsometricGameEditor::create(RequestedContainerInfo &requestedInfo, pika::St
 	}
 
 	
-
+	newMapSize = map.size;
 
 	return true;
 }
@@ -105,22 +105,8 @@ bool IsometricGameEditor::update(pika::Input input, pika::WindowState windowStat
 		return position;
 	};
 
-	for (int y = 0; y < map.size.y; y++)
-		for (int z = 0; z < map.size.z; z++)
-			for (int x = 0; x < map.size.x; x++)
-			{
-				auto b = map.getSafe({x,y,z});
-
-				if (b->get().x != 0)
-				{
-					glm::vec2 position = calculateBlockPos({x,y,z});
-
-					requestedInfo.consoleWrite("yes");
-					renderer.renderRectangle({position,size,size}, tiles, Colors_White, {}, 0,
-						tilesAtlas.get(b->get().x, b->get().y));
-				}
-			}
-
+	glm::ivec3 currentSelectedBlockDelete{-1};
+	glm::ivec3 currentSelectedBlockPlace{-1};
 
 	auto viewRect = renderer.getViewRect();
 
@@ -132,60 +118,136 @@ bool IsometricGameEditor::update(pika::Input input, pika::WindowState windowStat
 	glm::vec2 blockPositionScreen = lerp(glm::vec2(viewRect.x, viewRect.y),
 		glm::vec2(viewRect.x + viewRect.z, viewRect.y + viewRect.w),
 		glm::vec2(input.mouseX, input.mouseY) / glm::vec2(windowState.windowW, windowState.windowH));
-	
 
-	glm::ivec3 currentSelectedBlock{-1};
-	
-	if(input.rMouse.pressed())
+
+		for (int y = 0; y < map.size.y; y++)
+			for (int z = 0; z < map.size.z; z++)
+				for (int x = 0; x < map.size.x; x++)
+				{
+
+					auto checkPointInBox = [&](int x, int y, int z, bool reverse = 0)
+					{
+						auto b = map.getSafe({x,y,z});
+
+						if (!b) { return false; }
+
+						if ((b->get().x != 0 && !reverse)
+							|| (b->get().x == 0 && reverse)
+							)
+						{
+							glm::vec2 position = calculateBlockPos({x,y,z});
+							glm::vec4 box = renderer.toScreen({position, size, size});
+							//todo new functon
+
+							box.x += 1;
+							box.x /= 2.f;
+							box.x *= renderer.windowW;
+
+							box.y *= -1;
+							box.y += 1;
+							box.y /= 2.f;
+							box.y *= renderer.windowH;
+
+							box.z += 1;
+							box.z /= 2.f;
+							box.z *= renderer.windowW;
+
+							box.w *= -1;
+							box.w += 1;
+							box.w /= 2.f;
+							box.w *= renderer.windowH;
+
+							box.z = box.z - box.x;
+							box.w = box.w - box.y;
+
+							if (pointInBox(glm::vec2(input.mouseX, input.mouseY), box))
+							{
+								return true;
+							}
+
+						}
+
+						return false;
+					};
+
+					if (checkPointInBox(x,y,z))
+					{
+						currentSelectedBlockDelete = {x,y,z};
+
+						if (checkPointInBox(x + 1, y, z, true))
+						{
+							currentSelectedBlockPlace = {x + 1,y,z};
+						}
+
+						if (checkPointInBox(x, y + 1, z, true))
+						{
+							currentSelectedBlockPlace = {x,y + 1,z};
+						}
+
+						if (checkPointInBox(x, y, z + 1, true))
+						{
+							currentSelectedBlockPlace = {x,y,z + 1};
+						}
+					}
+
+				}
+
 	for (int y = 0; y < map.size.y; y++)
 		for (int z = 0; z < map.size.z; z++)
 			for (int x = 0; x < map.size.x; x++)
 			{
-
 				auto b = map.getSafe({x,y,z});
 
 				if (b->get().x != 0)
 				{
 					glm::vec2 position = calculateBlockPos({x,y,z});
-					glm::vec4 box = renderer.toScreen({position, size, size});
-					//todo new functon
-
-					box.x += 1;
-					box.x /= 2.f;
-					box.x *= renderer.windowW;
-
-					box.y *= -1;
-					box.y += 1;
-					box.y /= 2.f;
-					box.y *= renderer.windowH;
-
-					box.z += 1;
-					box.z /= 2.f;
-					box.z *= renderer.windowW;
 
-					box.w *= -1;
-					box.w += 1;
-					box.w /= 2.f;
-					box.w *= renderer.windowH;
+					renderer.renderRectangle({position,size,size}, tiles, Colors_White, {}, 0,
+						tilesAtlas.get(b->get().x, b->get().y));
+				}
 
-					box.z = box.z - box.x;
-					box.w = box.w - box.y;
+				if (currentSelectedBlockDelete == glm::ivec3{x, y, z})
+				{
+					glm::vec2 position = calculateBlockPos({x,y,z});
+				
+					renderer.renderRectangle({position,size,size}, tiles, Colors_White, {}, 0,
+						tilesAtlas.get(0, 1));
+				}
 
-					if(pointInBox(glm::vec2(input.mouseX, input.mouseY), box))
-					{
-						currentSelectedBlock = {x,y,z};
-					}
+				if (currentSelectedBlockPlace == glm::ivec3{x, y, z})
+				{
+					glm::vec2 position = calculateBlockPos({x,y,z});
 
+					renderer.renderRectangle({position,size,size}, tiles, {0.1,0.1,0.1,0.1}, {}, 0,
+						tilesAtlas.get(0, 1));
 				}
+			}
 
+	if (currentSelectedBlockDelete.x > -1)
+	{
+		if (
+			input.lMouse.pressed()
+			)
+		{
+			auto b = map.getSafe(currentSelectedBlockDelete);
+			if (b)
+			{
+				b->set(0, 0);
 			}
+		}
+	}
 
-	if (currentSelectedBlock.x > -1)
+	if (currentSelectedBlockPlace.x > -1)
 	{
-		auto b = map.getSafe(currentSelectedBlock);
-		if (b)
+		if (
+			input.rMouse.pressed()
+			)
 		{
-			b->set(0, 0);
+			auto b = map.getSafe(currentSelectedBlockPlace);
+			if (b)
+			{
+				b->set(currentBlock, 0);
+			}
 		}
 	}
 
@@ -229,6 +291,40 @@ bool IsometricGameEditor::update(pika::Input input, pika::WindowState windowStat
 
 	ImGui::NewLine();
 
+	//ImGui::DragInt3("Cursor pos", &currentSelectedBlockDelete[0], 1);
+	//currentSelectedBlock = glm::clamp(currentSelectedBlock, glm::ivec3{0}, map.size - glm::ivec3(1));
+
+	ImGui::NewLine();
+
+
+	ImGui::DragInt3("NewMapSize", &newMapSize[0]);
+
+	if (ImGui::Button("Resize Map"))
+	{
+		Map newMap;
+		newMap.init(newMapSize);
+
+		for (int x = 0; x < map.size.x; x++)
+			for (int y = 0; y < map.size.y; y++)
+				for (int z = 0; z < map.size.z; z++)
+				{
+
+					auto b = map.getSafe({x,y,z});
+
+					auto b2 = newMap.getSafe({x,y,z});
+
+					if (b2)
+					{
+						*b2 = *b;
+					}
+				}
+
+		map = std::move(newMap);
+	}
+
+	ImGui::NewLine();
+
+
 	loadedLevel.run(requestedInfo.requestedImguiIds);
 
 	if (ImGui::Button("save map"))
@@ -242,6 +338,9 @@ bool IsometricGameEditor::update(pika::Input input, pika::WindowState windowStat
 		}
 	}
 
+	ImGui::NewLine();
+
+
 
 
 	ImGui::End();

+ 2 - 0
Pika/gameplay/containers/isometricGame/isometricGameEditor.h

@@ -20,6 +20,8 @@ struct IsometricGameEditor: public Container
 	gl2d::Texture tiles;
 	gl2d::TextureAtlasPadding tilesAtlas;
 
+	glm::ivec3 newMapSize = {};
+
 	static ContainerStaticInfo containerInfo()
 	{
 		ContainerStaticInfo info = {};

二进制
Pika/resources/isoTiles/Isometric-Tiles.png


+ 7 - 4
Pika/resources/logs.txt

@@ -1,4 +1,7 @@
-#2024-01-03 15:37:45: Created container: IsometricGameEditor
-#2024-01-03 15:37:52: Destroyed continer: IsometricGameEditor #1
-#2024-01-03 15:37:53: Created container: IsometricGameEditor
-#2024-01-03 15:37:59: Destroyed continer: IsometricGameEditor #2
+#2024-01-03 16:04:06: Created container: IsometricGameEditor
+#2024-01-03 16:04:49: Reloaded dll
+#2024-01-03 16:07:06: Reloaded dll
+#2024-01-03 16:07:44: Reloaded dll
+#2024-01-03 16:07:58: Reloaded dll
+#2024-01-03 16:08:48: Reloaded dll
+#2024-01-03 16:10:43: Destroyed continer: IsometricGameEditor #1