Exemple #1
0
CInventory::CInventory()
{
	CInputManager::GetInstance()->RegisterKey("Down", eKey::DownArrow);
	CInputManager::GetInstance()->RegisterKey("Up", eKey::UpArrow);
	CInputManager::GetInstance()->RegisterKey("Craft", eKey::Enter);
	CInputManager::GetInstance()->RegisterKey("CraftAll", eKey::Shift);
	CInputManager::GetInstance()->RegisterKey("Escape", eKey::escape);

	m_nCursor = Bones;
	m_fPickUpTimer = FLASH_TIME;
	m_bPickUp = false;

	m_vIconPaths.push_back(L"../Game/Assets/Art/2D/Inventory/Failbot_Inv_Bone.dds");
	m_vIconPaths.push_back(L"../Game/Assets/Art/2D/Inventory/Failbot_Inv_Wood.dds");
	m_vIconPaths.push_back(L"../Game/Assets/Art/2D/Inventory/Failbot_Inv_Herb.dds");
	m_vIconPaths.push_back(L"../Game/Assets/Art/2D/Inventory/Failbot_Inv_Gunpowder.dds");
	m_vIconPaths.push_back(L"../Game/Assets/Art/2D/Inventory/Failbot_Inv_Bomb.dds");
	m_vIconPaths.push_back(L"../Game/Assets/Art/2D/Inventory/Failbot_Inv_Bridge.dds");
	m_vIconPaths.push_back(L"../Game/Assets/Art/2D/Inventory/Failbot_Inv_HealthPotion.dds");

#pragma region Background Image

	vector<TVertex2D> ScreenVerts;
	vector<unsigned int> ScreenIndicies;

	ScreenIndicies.push_back(0);
	ScreenIndicies.push_back(1);
	ScreenIndicies.push_back(2);

	ScreenIndicies.push_back(0);
	ScreenIndicies.push_back(2);
	ScreenIndicies.push_back(3);

	ScreenVerts.push_back // Top Left
		({
			{ -0.8f, 0.7f, -1.0f, 1 },
			{ 0, 0 }
	});

	ScreenVerts.push_back // Top Right
		({
			{ 0.6f, 0.7f, -1.0f, 1 },
			{ 1, 0 }
	});

	ScreenVerts.push_back // Bot Right
		({
			{ 0.6f, -0.7f, -1.0f, 1 },
			{ 1, 1 }
	});

	ScreenVerts.push_back // Bot Left
		({
			{ -0.8f, -0.7f, -1.0f, 1 },
			{ 0, 1 }
	});

	m_cpInventoryScreen = new CHUDMesh(ScreenIndicies, ScreenVerts, GRAPHICS->GetVertexShader2D(), GRAPHICS->GetPixelShader2D(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Inventory/Failbot_Inv_Background.dds");
	m_cpInventoryScreen->GetRender() = false;
	m_cpInventoryScreen->GetTransparent() = true;
	GRAPHICS->AddRenderMesh(m_cpInventoryScreen);

#pragma endregion

#pragma region Icons and Boarders Set Up

	float yOffset = 0.1275f;

	//icon positions
	float fIconLeft = -0.61f;
	float fIconRight = -0.535f;
	float fIconTop = 0.375f;
	float fIconBottom = 0.3f;

	//boarder positions
	float fBoarderLeft = -0.635f;
	float fBoarderRight = -0.51f;
	float fBoarderTop = 0.4f;
	float fBoarderBottom = 0.275f;

	for (unsigned int i = 0; i < ItemCount; i++)
	{
		vector<unsigned int> Indicies;
		Indicies.push_back(0);
		Indicies.push_back(1);
		Indicies.push_back(2);
		Indicies.push_back(0);
		Indicies.push_back(2);
		Indicies.push_back(3);

		//icon image
		vector<TVertex2D> Verts;
		Verts.push_back // Top Left
			({
				{ fIconLeft, fIconTop, -1.0f, 1 },
				{ 0, 0 }
		});

		Verts.push_back // Top Right
			({
				{ fIconRight, fIconTop, -1.0f, 1 },
				{ 1, 0 }
		});

		Verts.push_back // Bot Right
			({
				{ fIconRight, fIconBottom, -1.0f, 1 },
				{ 1, 1 }
		});

		Verts.push_back // Bot Left
			({
				{ fIconLeft, fIconBottom, -1.0f, 1 },
				{ 0, 1 }

		});

		m_vcIcons.push_back(new CHUDMesh(Indicies, Verts, GRAPHICS->GetVertexShader2D(), GRAPHICS->GetPixelShader2D(), nullptr, nullptr, nullptr, m_vIconPaths[i]));
		m_vcIcons[i]->GetRender() = false;
		m_vcIcons[i]->GetTransparent() = true;


		//boarder image for this icon
		vector<TVertex2D> BoarderVerts;
		BoarderVerts.push_back // Top Left
			({
				{ fBoarderLeft, fBoarderTop, -1.0f, 1 },
				{ 0, 0 }
		});

		BoarderVerts.push_back // Top Right
			({
				{ fBoarderRight, fBoarderTop, -1.0f, 1 },
				{ 1, 0 }
		});

		BoarderVerts.push_back // Bot Right
			({
				{ fBoarderRight, fBoarderBottom, -1.0f, 1 },
				{ 1, 1 }
		});

		BoarderVerts.push_back // Bot Left
			({
				{ fBoarderLeft, fBoarderBottom, -1.0f, 1 },
				{ 0, 1 }
		});

		m_vcBoarder.push_back(new CHUDMesh(Indicies, BoarderVerts, GRAPHICS->GetVertexShader2D(), GRAPHICS->GetPixelShader2D(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Inventory/Failbot_Icon_Normal.dds"));
		m_vcBoarder[i]->GetRender() = false;
		m_vcBoarder[i]->GetTransparent() = true;

		GRAPHICS->AddRenderMesh(m_vcBoarder[i]);
		GRAPHICS->AddRenderMesh(m_vcIcons[i]);

		fIconTop -= yOffset;
		fIconBottom -= yOffset;
		fBoarderTop -= yOffset;
		fBoarderBottom -= yOffset;

		if (i == Gunpowder)
		{
			fIconTop -= 0.1f;
			fIconBottom -= 0.1f;
			fBoarderTop -= 0.1f;
			fBoarderBottom -= 0.1f;
		}
		if (i == Bomb)
		{
			fIconTop -= 0.0075f;
			fIconBottom -= 0.0075f;
			fBoarderTop -= 0.0075f;
			fBoarderBottom -= 0.0075f;
		}
	}

	m_vcBoarder[m_nCursor]->SetTexture(L"../Game/Assets/Art/2D/Inventory/Failbot_Icon_Selected.dds");

#pragma endregion

#pragma region CurItem

	vector<unsigned int> vIndicies;
	vIndicies.push_back(0);
	vIndicies.push_back(1);
	vIndicies.push_back(2);
	vIndicies.push_back(0);
	vIndicies.push_back(2);
	vIndicies.push_back(3);

	vector<TVertex2D> vVerts;
	vVerts.push_back // Top Left
		({
			{ 0.0f, 0.0f, -1.0f, 1 },
			{ 0, 0 }
	});

	vVerts.push_back // Top Right
		({
			{ 0.175f, 0.0f, -1.0f, 1 },
			{ 1, 0 }
	});

	vVerts.push_back // Bot Right
		({
			{ 0.175f, -0.175f, -1.0f, 1 },
			{ 1, 1 }
	});

	vVerts.push_back // Bot Left
		({
			{ 0.0f, -0.175f, -1.0f, 1 },
			{ 0, 1 }
	});

	m_cpSelectedIcon = new CHUDMesh(vIndicies, vVerts, GRAPHICS->GetVertexShader2D(), GRAPHICS->GetPixelShader2D(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Inventory/Failbot_Icon_Normal.dds");
	m_cpSelectedIcon->GetRender() = false;
	m_cpSelectedIcon->GetTransparent() = true;
	TranslateLocalX(m_cpSelectedIcon->GetTransformMatrix(), -0.3f);
	TranslateLocalY(m_cpSelectedIcon->GetTransformMatrix(), 0.325f);
	GRAPHICS->AddRenderMesh(m_cpSelectedIcon);


	vVerts.clear();
	vVerts.push_back // Top Left
		({
			{ 0.0f, 0.0f, -1.0f, 1 },
			{ 0, 0 }
	});

	vVerts.push_back // Top Right
		({
			{ 0.125f, 0.0f, -1.0f, 1 },
			{ 1, 0 }
	});

	vVerts.push_back // Bot Right
		({
			{ 0.125f, -0.125f, -1.0f, 1 },
			{ 1, 1 }
	});

	vVerts.push_back // Bot Left
		({
			{ 0.0f, -0.125f, -1.0f, 1 },
			{ 0, 1 }
	});

	m_cpCurrentItem = new CHUDMesh(vIndicies, vVerts, GRAPHICS->GetVertexShader2D(), GRAPHICS->GetPixelShader2D(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Inventory/Failbot_Inv_Bone.dds");
	m_cpCurrentItem->GetRender() = false;
	m_cpCurrentItem->GetTransparent() = true;
	TranslateLocalX(m_cpCurrentItem->GetTransformMatrix(), -0.275f);
	TranslateLocalY(m_cpCurrentItem->GetTransformMatrix(), 0.3f);
	GRAPHICS->AddRenderMesh(m_cpCurrentItem);

#pragma endregion

#pragma region Input Images Set Up

	m_vInputImgPaths.push_back(L"../Game/Assets/Art/2D/Inventory/UpArrow_Keyboard.dds");
	m_vInputImgPaths.push_back(L"../Game/Assets/Art/2D/Inventory/DownArrow_Keyboard.dds");
	m_vInputImgPaths.push_back(L"../Game/Assets/Art/2D/Inventory/Enter_Keyboard.dds");
	m_vInputImgPaths.push_back(L"../Game/Assets/Art/2D/Inventory/SpaceBar_Keyboard.dds");

	vIndicies.clear();
	vIndicies.push_back(0);
	vIndicies.push_back(1);
	vIndicies.push_back(2);
	vIndicies.push_back(0);
	vIndicies.push_back(2);
	vIndicies.push_back(3);

	vVerts.clear();
	vVerts.push_back // Top Left
		({
			{ 0.0f, 0.0f, -1.0f, 1 },
			{ 0, 0 }
	});

	vVerts.push_back // Top Right
		({
			{ 0.2f, 0.0f, -1.0f, 1 },
			{ 1, 0 }
	});

	vVerts.push_back // Bot Right
		({
			{ 0.2f, -0.2f, -1.0f, 1 },
			{ 1, 1 }
	});

	vVerts.push_back // Bot Left
		({
			{ 0.0f, -0.2f, -1.0f, 1 },
			{ 0, 1 }
	});

	for (unsigned int i = 0; i < NUM_INPUT_IMAGES; i++)
	{
		m_cpInputImgs[i] = new CHUDMesh(vIndicies, vVerts, GRAPHICS->GetVertexShader2D(), GRAPHICS->GetPixelShader2D(), nullptr, nullptr, nullptr, m_vInputImgPaths[i]);
		m_cpInputImgs[i]->GetRender() = false;
		m_cpInputImgs[i]->GetTransparent() = true;
		GRAPHICS->AddRenderMesh(m_cpInputImgs[i]);
	}

	TranslateLocalX(m_cpInputImgs[0]->GetTransformMatrix(), -0.8f);//arrow up
	TranslateLocalY(m_cpInputImgs[0]->GetTransformMatrix(), 0.1f);
	TranslateLocalX(m_cpInputImgs[1]->GetTransformMatrix(), -0.8f);//arrow down
	TranslateLocalY(m_cpInputImgs[1]->GetTransformMatrix(), -0.1f);

	m_cpInputImgs[2]->GetVertex2DArr()[0].m_fPosition[1] = 0.1f;//enter key
	m_cpInputImgs[2]->GetVertex2DArr()[1].m_fPosition[1] = 0.1f;
	TranslateLocalX(m_cpInputImgs[2]->GetTransformMatrix(), -0.35f);
	TranslateLocalY(m_cpInputImgs[2]->GetTransformMatrix(), -0.5f);

	m_cpInputImgs[3]->GetVertex2DArr()[1].m_fPosition[0] = 0.2f;//space bar
	m_cpInputImgs[3]->GetVertex2DArr()[2].m_fPosition[0] = 0.2f;
	m_cpInputImgs[3]->GetVertex2DArr()[0].m_fPosition[1] = 0.1f;
	m_cpInputImgs[3]->GetVertex2DArr()[1].m_fPosition[1] = 0.1f;
	TranslateLocalX(m_cpInputImgs[3]->GetTransformMatrix(), 0.05f);
	TranslateLocalY(m_cpInputImgs[3]->GetTransformMatrix(), -0.5f);

#pragma endregion

#pragma region Crafting Bar Set Up

	vector<TVertex2D> barVerts;
	vector<unsigned int> barIndicies;

	barIndicies.push_back(0);
	barIndicies.push_back(1);
	barIndicies.push_back(2);
	barIndicies.push_back(0);
	barIndicies.push_back(2);
	barIndicies.push_back(3);

	float fxBar = -0.4f;
	float fyBar = -0.3f;

	float fwBar = 0.55f;
	float fhBar = 0.1f;

	m_fCraftBarSize = fwBar;
	m_fCraftBarStartX = fxBar;
	m_fCraftTime = 0.0f;
	m_bCrafting = false;
	m_bCraftAll = false;
	m_bAbleToCraft = false;

	barVerts.push_back // Top Left
		({
			{ fxBar, fyBar, -1.0f, 1 },
			{ 0, 0 }
	});

	barVerts.push_back // Top Right
		({
			{ fxBar + fwBar, fyBar, -1.0f, 1 },
			{ 1, 0 }
	});

	barVerts.push_back // Bot Right
		({
			{ fxBar + fwBar, fyBar - fhBar, -1.0f, 1 },
			{ 1, 1 }
	});

	barVerts.push_back // Bot Left
		({
			{ fxBar, fyBar - fhBar, -1.0f, 1 },
			{ 0, 1 }
	});

	m_cpCraftingBar = new CHUDMesh(barIndicies, barVerts, GRAPHICS->GetVertexShader2D(), GRAPHICS->GetPixelShader2D(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Inventory/Failbot_Craft_Bar.dds");
	m_cpCraftingBar->GetRender() = false;
	m_cpCraftingBar->GetTransparent() = true;
	TranslateLocalX(m_cpCraftingBar->GetTransformMatrix(), 0.35f);
	TranslateLocalY(m_cpCraftingBar->GetTransformMatrix(), 0.0875f);
	GRAPHICS->AddRenderMesh(m_cpCraftingBar);

#pragma endregion

	m_CurrentStock[Bones] = 0;
	m_CurrentStock[Wood] = 0;
	m_CurrentStock[Herb] = 0;
	m_CurrentStock[Gunpowder] = 0;
	m_CurrentStock[Bomb] = 0;
	m_CurrentStock[Bridge] = 0;
	m_CurrentStock[HealthPotion] = 0;

	m_vcBoarder[m_nCursor]->SetTexture(L"../Game/Assets/Art/2D/Inventory/Failbot_Icon_Selected.dds");
}
void Camera::Update()
{
	if (GetCursorPos(&m_nCurrentPos) && GetAsyncKeyState(0x02))
	{
		float fDeltaX = (float)(m_nCurrentPos.x - m_nPreviousPos.x);
		float fDeltaY = (float)(m_nCurrentPos.y - m_nPreviousPos.y);

		// Cursor Wrap //
		if (m_nCurrentPos.x < 1) // Left
			SetCursorPos(SCREEN_WIDTH - 2, m_nCurrentPos.y);
		if (m_nCurrentPos.y < 1) // Top
			SetCursorPos(m_nCurrentPos.x, SCREEN_HEIGHT - 2);
		if (m_nCurrentPos.x > SCREEN_WIDTH - 2) // Right
			SetCursorPos(1, m_nCurrentPos.y);
		if (m_nCurrentPos.y > SCREEN_HEIGHT - 2) // Bottom
			SetCursorPos(m_nCurrentPos.x, 1);

		// - Rotate Camera - //
		if (fDeltaX || fDeltaY)
		{
			fDeltaX *= SENSITIVITY;
			fDeltaY *= SENSITIVITY;

			// Store Position //
			float fMatrixPosX = m_fViewMatrix.m[3][0];
			float fMatrixPosY = m_fViewMatrix.m[3][1];
			float fMatrixPosZ = m_fViewMatrix.m[3][2];
			float fMatrixPosW = m_fViewMatrix.m[3][3];

			// Set Position To World Center // Global rotation becomes same as local
			m_fViewMatrix.m[3][0] = 0;
			m_fViewMatrix.m[3][1] = 0;
			m_fViewMatrix.m[3][2] = 0;
			m_fViewMatrix.m[3][3] = 0;

			// Rotate Globally On Y-Axis //
			RotateGlobalY(m_fViewMatrix, fDeltaX);

			if (m_fCameraAngle + fDeltaY <  90 &&
				m_fCameraAngle + fDeltaY > -90) // No x-axis 360's
			{
				// Update Angle //
				m_fCameraAngle += fDeltaY;

				// Rotate Locally On X-Axis //
				RotateLocalX(m_fViewMatrix, fDeltaY);
			}

			// Restore Position //
			m_fViewMatrix.m[3][0] = fMatrixPosX;
			m_fViewMatrix.m[3][1] = fMatrixPosY;
			m_fViewMatrix.m[3][2] = fMatrixPosZ;
			m_fViewMatrix.m[3][3] = fMatrixPosW;
		}
	}

	// Snapping Fix //
	if (m_nCurrentPos.x < 1 ||
		m_nCurrentPos.y < 1 ||
		m_nCurrentPos.x > SCREEN_WIDTH - 2 ||
		m_nCurrentPos.y > SCREEN_HEIGHT - 2)
	{
		GetCursorPos(&m_nCurrentPos);
	}

	m_nPreviousPos = m_nCurrentPos;

	// Distace Per Second //
	float fBoostSpeed = 90 * DELTA_TIME;
	float fNormalSpeed = 30 * DELTA_TIME;

	// - Key Movement - //
	if (GetAsyncKeyState(0x57)) // W
	{
		if (GetAsyncKeyState(0x10))
			TranslateLocalZ(m_fViewMatrix, fBoostSpeed); // Boost
		else
			TranslateLocalZ(m_fViewMatrix, fNormalSpeed); // Normal
	}
	if (GetAsyncKeyState(0x53)) // S
	{
		if (GetAsyncKeyState(0x10))
			TranslateLocalZ(m_fViewMatrix, -fBoostSpeed); // Boost
		else
			TranslateLocalZ(m_fViewMatrix, -fNormalSpeed); // Normal
	}
	if (GetAsyncKeyState(0x41)) // A
	{
		if (GetAsyncKeyState(0x10))
			TranslateLocalX(m_fViewMatrix, -fBoostSpeed); // Boost
		else
			TranslateLocalX(m_fViewMatrix, -fNormalSpeed); // Normal
	}
	if (GetAsyncKeyState(0x44)) // D
	{
		if (GetAsyncKeyState(0x10))
			TranslateLocalX(m_fViewMatrix, fBoostSpeed); // Boost
		else
			TranslateLocalX(m_fViewMatrix, fNormalSpeed); // Normal
	}

	GRAPHICS->GetViewMatrix() = m_fViewMatrix;
}