Browse Source

working at items

meemknight 1 year ago
parent
commit
a8a9dc08a5

+ 96 - 21
Pika/gameplay/containers/isometricGame/isometricGame.cpp

@@ -19,6 +19,16 @@ bool IsometricGame::create(RequestedContainerInfo &requestedInfo, pika::StaticSt
 		requestedInfo, true);
 		requestedInfo, true);
 	playerAtlas = gl2d::TextureAtlas(5, 4);
 	playerAtlas = gl2d::TextureAtlas(5, 4);
 
 
+	itemsSprite = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "iso/tiles/items.png",
+		requestedInfo, true);
+	itemsAtlas = gl2d::TextureAtlas(3, 1);
+
+	itemFrameSprite = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "iso/tiles/ui.png",
+		requestedInfo, true);
+
+
+	font = pika::gl2d::loadFont(PIKA_RESOURCES_PATH "mcDungeons/CommodorePixeled.ttf", requestedInfo);
+
 
 
 	for (int i = 0; i < MAPS_COUNT; i++)
 	for (int i = 0; i < MAPS_COUNT; i++)
 	{
 	{
@@ -137,27 +147,20 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 #pragma endregion
 #pragma endregion
 
 
 
 
-#pragma region move
-
-	float cameraSpeed = input.deltaTime * size * 2.f;
+#pragma region UI1
 
 
-	if (input.buttons[pika::Button::A].held())
+	glm::vec4 uiBox = {};
 	{
 	{
-		renderer.currentCamera.position.x -= cameraSpeed;
-	}
-	if (input.buttons[pika::Button::D].held())
-	{
-		renderer.currentCamera.position.x += cameraSpeed;
-	}
+		glui::Frame f({0, 0, windowState.windowW, windowState.windowH});
+		uiBox = glui::Box().xLeftPerc(0.05).yTopPerc(0.02)
+			.xDimensionPercentage(0.4).yDimensionPercentage(0.2);
+
+		float boxSize = std::min(uiBox.z / 3.f, uiBox.w);
+		uiBox.z = boxSize * 3;
+		uiBox.w = boxSize;
 
 
-	if (input.buttons[pika::Button::W].held())
-	{
-		renderer.currentCamera.position.y -= cameraSpeed;
-	}
-	if (input.buttons[pika::Button::S].held())
-	{
-		renderer.currentCamera.position.y += cameraSpeed;
 	}
 	}
+
 #pragma endregion
 #pragma endregion
 
 
 
 
@@ -175,8 +178,11 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 
 
 #pragma region camera
 #pragma region camera
 
 
-	renderer.currentCamera.follow(calculateBlockPos({map.size.x / 2-1, 1, map.size.z / 2}),
-		100, 0, 0, windowState.windowW, windowState.windowH);
+	//renderer.currentCamera.follow(calculateBlockPos({map.size.x / 2-1, 1, map.size.z / 2}),
+	//	100, 0, 0, windowState.windowW, windowState.windowH);
+
+	renderer.currentCamera.follow(calculateBlockPos({glm::vec3(playerPosition) + playerAnimations.delta}),
+		input.deltaTime*90, 1, 100, windowState.windowW, windowState.windowH);
 
 
 #pragma endregion
 #pragma endregion
 
 
@@ -239,7 +245,9 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 							box.z = box.z - box.x;
 							box.z = box.z - box.x;
 							box.w = box.w - box.y;
 							box.w = box.w - box.y;
 
 
-							if (IsometricGameEditor::pointInBox(glm::vec2(input.mouseX, input.mouseY), box))
+							if (IsometricGameEditor::pointInBox(glm::vec2(input.mouseX, input.mouseY), box)
+								&& !IsometricGameEditor::pointInBox(glm::vec2(input.mouseX, input.mouseY), uiBox)
+								)
 							{
 							{
 								return true;
 								return true;
 							}
 							}
@@ -561,7 +569,6 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 				tryBlock(0, 1);
 				tryBlock(0, 1);
 				tryBlock(0, -1);
 				tryBlock(0, -1);
 
 
-
 			}
 			}
 
 
 		}
 		}
@@ -597,6 +604,16 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 				//flip lever
 				//flip lever
 				b->secondType = !b->get().y;
 				b->secondType = !b->get().y;
 			}
 			}
+			else if (b->get().x == IsometricGameEditor::Blocks::redstone)
+			{
+				b->set(0,0);
+				redstoneCount++;
+			}
+			else if (b->get().x == IsometricGameEditor::Blocks::redstoneTorch)
+			{
+				b->set(0, 0);
+				redstoneTorchesCount++;
+			}
 		}
 		}
 
 
 	}
 	}
@@ -604,6 +621,64 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 
 
 #pragma endregion
 #pragma endregion
 
 
+#pragma region UI2
+
+	renderer.pushCamera();
+	{
+		glui::Frame f(uiBox);
+		renderer.renderRectangle(uiBox, {0.1,0.1,0.1,0.5});
+		
+		float boxSize = uiBox.z/3.f;
+
+		renderer.renderRectangle({uiBox.x, uiBox.y, boxSize, boxSize}, itemsSprite, {1,1,1,0.9},
+			{}, 0.f, itemsAtlas.get(0,0));
+
+		renderer.renderRectangle({uiBox.x + boxSize, uiBox.y, boxSize, boxSize}, itemsSprite, {1,1,1,0.9},
+			{}, 0.f, itemsAtlas.get(1, 0));
+
+		renderer.renderRectangle({uiBox.x + boxSize * 2, uiBox.y, boxSize, boxSize}, itemsSprite, {1,1,1,0.9},
+			{}, 0.f, itemsAtlas.get(2, 0));
+
+		if (itemSelected != -1)
+		{
+			renderer.renderRectangle({uiBox.x + boxSize * itemSelected, uiBox.y, boxSize, boxSize}, itemFrameSprite);
+		}
+
+		renderer.renderText({uiBox.x + boxSize*0.75, uiBox.y + boxSize * 0.75},
+			std::to_string(redstoneCount).c_str(), font, Colors_White);
+
+		renderer.renderText({uiBox.x + boxSize * 1.75, uiBox.y + boxSize * 0.75},
+			std::to_string(redstoneTorchesCount).c_str(), font, Colors_White);
+
+		renderer.renderText({uiBox.x + boxSize * 2.75, uiBox.y + boxSize * 0.75},
+			std::to_string(foodCount).c_str(), font, Colors_White);
+
+
+		if (input.lMouse.pressed())
+		{
+			if (IsometricGameEditor::pointInBox(glm::vec2(input.mouseX, input.mouseY), {uiBox.x, uiBox.y, boxSize, boxSize}))
+			{
+				itemSelected = 0;
+			}
+
+			if (IsometricGameEditor::pointInBox(glm::vec2(input.mouseX, input.mouseY), {uiBox.x + boxSize, uiBox.y, boxSize, boxSize}))
+			{
+				itemSelected = 1;
+			}
+
+			if (IsometricGameEditor::pointInBox(glm::vec2(input.mouseX, input.mouseY), {uiBox.x + boxSize * 2, uiBox.y, boxSize, boxSize}))
+			{
+				itemSelected = 2;
+			}
+		}
+
+		
+	}
+	renderer.popCamera();
+
+#pragma endregion
+
+
 
 
 
 
 	ImGui::Begin("Game debug");
 	ImGui::Begin("Game debug");

+ 14 - 1
Pika/gameplay/containers/isometricGame/isometricGame.h

@@ -25,6 +25,19 @@ struct IsometricGame: public Container
 	gl2d::Texture playerSprite;
 	gl2d::Texture playerSprite;
 	gl2d::TextureAtlas playerAtlas;
 	gl2d::TextureAtlas playerAtlas;
 
 
+	gl2d::Texture itemsSprite;
+	gl2d::TextureAtlas itemsAtlas;
+
+	gl2d::Font font;
+
+	gl2d::Texture itemFrameSprite;
+
+
+	int redstoneCount = 0;
+	int redstoneTorchesCount = 0;
+	int foodCount = 0;
+	int itemSelected = -1;
+
 	glm::ivec3 playerPosition = {7, 1, 7};
 	glm::ivec3 playerPosition = {7, 1, 7};
 
 
 	struct PlayerAnimations
 	struct PlayerAnimations
@@ -44,7 +57,7 @@ struct IsometricGame: public Container
 	static ContainerStaticInfo containerInfo()
 	static ContainerStaticInfo containerInfo()
 	{
 	{
 		ContainerStaticInfo info = {};
 		ContainerStaticInfo info = {};
-		info.defaultHeapMemorySize = pika::MB(10);
+		info.defaultHeapMemorySize = pika::MB(20);
 
 
 
 
 		info.requestImguiFbo = true;
 		info.requestImguiFbo = true;

BIN
Pika/resources/iso/tiles/items.png


BIN
Pika/resources/iso/tiles/ui.png


+ 2 - 5
Pika/resources/logs.txt

@@ -1,5 +1,2 @@
-#2024-01-08 13:22:59: Created container: IsometricGame
-#2024-01-08 13:23:20: Reloaded dll
-#2024-01-08 13:26:39: Reloaded dll
-#2024-01-08 13:28:38: Reloaded dll
-#2024-01-08 13:29:14: Destroyed continer: IsometricGame #1
+#2024-01-08 14:41:14: Created container: IsometricGame
+#2024-01-08 14:41:38: Destroyed continer: IsometricGame #1