Example #1
0
File: VoxGUI.cpp Project: rzh/Vox
void VoxGame::CameraModeChanged()
{
	if (m_pDebugCameraOptionBox->GetToggled())
	{
		SetCameraMode(CameraMode_Debug);

		TurnCursorOn(true, false);
	}
	else if (m_pMouseRotateCameraOptionBox->GetToggled())
	{
		SetCameraMode(CameraMode_MouseRotate);
		InitializeCameraRotation();

		TurnCursorOff(false);
	}
	else if (m_pAutoCameraOptionBox->GetToggled())
	{
		SetCameraMode(CameraMode_AutoCamera);
		InitializeCameraRotation();

		TurnCursorOff(false);
	}
	else if (m_pFrontendCameraOptionBox->GetToggled())
	{
		SetCameraMode(CameraMode_Frontend);

		TurnCursorOn(true, false);
	}
}
Example #2
0
void VoxGame::MouseLeftPressed()
{
	if (m_pVoxWindow->IsCursorOn())
	{
		m_pGUI->MousePressed(MOUSE_BUTTON1);
	}

	if (m_pVoxWindow->IsCursorOn() == false || !m_pGUI->IsMouseInteractingWithGUIComponent(false))
	{
		m_currentX = m_pVoxWindow->GetCursorX();
		m_currentY = m_pVoxWindow->GetCursorY();
		m_pressedX = m_currentX;
		m_pressedY = m_currentY;

		if (m_gameMode == GameMode_Debug || m_cameraMode == CameraMode_Debug)
		{
			// Turn cursor off
			if (m_pVoxWindow->IsCursorOn() == true)
			{
				TurnCursorOff();
			}

			m_bCameraRotate = true;
		}
		else if (m_gameMode == GameMode_Game)
		{
			m_bAttackPressed_Mouse = true;
		}
	}
}
Example #3
0
void VoxGame::MouseLeftPressed()
{
	m_bPressedCursorDown = true;

	if (IsCursorOn())
	{
		m_pGUI->MousePressed(MOUSE_BUTTON1);
	}

	if (IsCursorOn() == false || !m_pGUI->IsMouseInteractingWithGUIComponent(false))
	{
		m_currentX = m_pVoxWindow->GetCursorX();
		m_currentY = m_pVoxWindow->GetCursorY();
		m_pressedX = m_currentX;
		m_pressedY = m_currentY;

		if (m_gameMode == GameMode_Debug || m_cameraMode == CameraMode_Debug)
		{
			// Turn cursor off
			if (IsCursorOn() == true)
			{
				TurnCursorOff(false);
			}

			m_bCameraRotate = true;
		}
		else if (m_gameMode == GameMode_Game)
		{
			m_bAttackPressed_Mouse = true;
		}
	}

	// For front-end character selection
	if (m_gameMode == GameMode_FrontEnd && !m_pGUI->IsMouseInteractingWithGUIComponent(false))
	{
		if (m_bNamePickingSelected) 
		{
			m_pNPCManager->UpdateNamePickingSelection(m_pickedObject);
		}
		else
		{
			m_pNPCManager->UpdateNamePickingSelection(-1);
		}
	}

	// For front-end credits screen advancement
	if (m_gameMode == GameMode_FrontEnd && m_pFrontendManager->GetFrontendScreen() == FrontendScreen_Credits)
	{
		m_pFrontendManager->GotoNextCreditScreen();
	}
}
Example #4
0
void VoxGame::UpdateKeyboardControls(float dt)
{
	GameMode gameMode = GetGameMode();

	if (gameMode == GameMode_Debug || m_cameraMode == CameraMode_Debug)
	{
		// Keyboard camera movements
		if (m_bKeyboardForward)
		{
			m_pGameCamera->Fly(20.0f * dt, true);
		}
		if (m_bKeyboardBackward)
		{
			m_pGameCamera->Fly(-20.0f * dt, true);
		}
		if (m_bKeyboardStrafeLeft)
		{
			m_pGameCamera->Strafe(-20.0f * dt, true);
		}
		if (m_bKeyboardStrafeRight)
		{
			m_pGameCamera->Strafe(20.0f * dt, true);
		}
		if (m_bKeyboardUp)
		{
			m_pGameCamera->Levitate(20.0f * dt, true);
		}
		if (m_bKeyboardDown)
		{
			m_pGameCamera->Levitate(-20.0f * dt, true);
		}
	}
	else if (gameMode == GameMode_Game)
	{
		// Pause menu
		if (m_bKeyboardMenu)
		{
			m_bKeyboardMenu = false;

			if (IsGUIWindowStillDisplayed())
			{
				CloseAllGUIWindows();

				if (IsGUIWindowStillDisplayed() == false)
				{
					TurnCursorOff(false);
				}
			}
			else
			{
				if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_None)
				{
					SetPauseMenu();
				}
				else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_PauseMenu)
				{
					UnsetPauseMenu();
				}
				else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_OptionsMenu)
				{
					m_pFrontendManager->SetFrontendScreen(FrontendScreen_PauseMenu);
				}
				else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_ModMenu)
				{
					m_pFrontendManager->SetFrontendScreen(FrontendScreen_PauseMenu);
				}
			}

			// Cancel quit popup menu with escape button
			if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_QuitPopup)
			{
				VoxGame::GetInstance()->CancelQuitPopup();
			}
		}

		if (m_pPlayer->IsDead() == false)
		{
			if (m_bPaused == false)  // If we are paused, don't allow gameplay control movements
			{
				if (IsGUIWindowStillDisplayed() == true)
				{
					// Reset movement speed since we have a GUI window open
					m_movementSpeed = 0.0f;
				}
				else
				{
					// Jumping
					if (m_bKeyboardSpace)
					{
						m_pPlayer->Jump();
					}

					// Attacking
					if (m_bAttackPressed_Mouse && m_bCanDoAttack_Mouse)
					{
						// Check interactions
						bool interaction = CheckInteractions();
						if (interaction == false)
						{
							m_pPlayer->PressAttack();
						}

						m_bCanDoAttack_Mouse = false;
					}
					if (m_bAttackReleased_Mouse)
					{
						m_pPlayer->ReleaseAttack();
						m_bAttackReleased_Mouse = false;
					}

					// Player movements
					bool resetMovementVector = false;
					if (m_bKeyboardForward == false && m_bKeyboardBackward == false && m_bKeyboardStrafeLeft == false && m_bKeyboardStrafeRight == false)
					{
						// Reduce the movement speed (drag)
						m_movementSpeed -= m_maxMovementSpeed / (m_movementDragTime / dt);

						if (m_movementSpeed <= 0.0f)
						{
							m_movementSpeed = 0.0f;
							m_keyboardMovement = false;
							m_pPlayer->StopMoving();
						}
					}
					else
					{
						m_keyboardMovement = true;

						// Increase the movement speed since we are pressing a movement key
						m_movementSpeed += m_maxMovementSpeed / (m_movementIncreaseTime / dt);

						// Don't allow faster than max movement
						if (m_movementSpeed > m_maxMovementSpeed)
						{
							m_movementSpeed = m_maxMovementSpeed;
						}
					}

					float targetModeMovementRatio = 0.65f;

					// Forwards, backwards, strafe, left, right directional movement
					if (m_bKeyboardForward)
					{
						if (resetMovementVector == false)
						{
							m_movementDirection = vec3(0.0f, 0.0f, 0.0f);
							resetMovementVector = true;
						}

						if (m_pPlayer->GetTargetEnemy() == NULL)
						{
							vec3 cameraRight = m_pGameCamera->GetRight();
							vec3 playerUp = m_pPlayer->GetUpVector();
							vec3 moveDirection = normalize(cross(cameraRight, playerUp));
							m_movementDirection -= moveDirection;
						}
						else
						{
							m_pPlayer->Move(m_movementSpeed * targetModeMovementRatio * dt);
						}
					}

					if (m_bKeyboardBackward)
					{
						if (resetMovementVector == false)
						{
							m_movementDirection = vec3(0.0f, 0.0f, 0.0f);
							resetMovementVector = true;
						}

						if (m_pPlayer->GetTargetEnemy() == NULL)
						{
							vec3 cameraRight = m_pGameCamera->GetRight();
							vec3 playerUp = m_pPlayer->GetUpVector();
							vec3 moveDirection = normalize(cross(cameraRight, playerUp));
							m_movementDirection += moveDirection;
						}
						else
						{
							m_pPlayer->Move(-m_movementSpeed * targetModeMovementRatio * dt);
						}
					}

					if (m_bKeyboardStrafeLeft)
					{
						if (resetMovementVector == false)
						{
							m_movementDirection = vec3(0.0f, 0.0f, 0.0f);
							resetMovementVector = true;
						}

						if (m_pPlayer->GetTargetEnemy() == NULL)
						{
							vec3 cameraRight = m_pGameCamera->GetRight();
							vec3 moveDirection = -cameraRight;
							m_movementDirection += moveDirection;
						}
						else
						{
							m_targetCameraXAxisAmount_Target += (0.75f * dt);
							if (m_targetCameraXAxisAmount_Target > 1.0f)
							{
								m_targetCameraXAxisAmount_Target = 1.0f;
							}

							m_pPlayer->Strafe(m_movementSpeed * targetModeMovementRatio * dt);
						}
					}

					if (m_bKeyboardStrafeRight)
					{
						if (resetMovementVector == false)
						{
							m_movementDirection = vec3(0.0f, 0.0f, 0.0f);
							resetMovementVector = true;
						}

						if (m_pPlayer->GetTargetEnemy() == NULL)
						{
							vec3 cameraRight = m_pGameCamera->GetRight();
							vec3 moveDirection = -cameraRight;
							m_movementDirection -= moveDirection;
						}
						else
						{
							m_targetCameraXAxisAmount_Target -= (0.75f * dt);
							if (m_targetCameraXAxisAmount_Target < -1.0f)
							{
								m_targetCameraXAxisAmount_Target = -1.0f;
							}

							m_pPlayer->Strafe(-m_movementSpeed * targetModeMovementRatio * dt);
						}
					}

					if (length(m_movementDirection) > 0.001f && m_movementSpeed > m_movementStopThreshold)
					{
						bool shouldChangePlayerFacing = (m_cameraMode != CameraMode_FirstPerson);

						m_movementDirection = normalize(m_movementDirection);
						vec3 amountMoved = m_pPlayer->MoveAbsolute(m_movementDirection, m_movementSpeed * dt, shouldChangePlayerFacing);
						m_pGameCamera->SetFakePosition(m_pGameCamera->GetFakePosition() + amountMoved);
					}
				}
			}
		}
	}
}
Example #5
0
void VoxGame::KeyReleased(int key, int scancode, int mods)
{
	m_pGUI->KeyReleased(key, mods);

	if (m_pGUI->IsKeyboardInteractingWithGUIComponent() && key != GLFW_KEY_ESCAPE)
	{
		return;  // For textbox entry
	}

	switch (key)
	{
		// Player movement
		case GLFW_KEY_W:
		{
			m_bKeyboardForward = false;
			break;
		}
		case GLFW_KEY_S:
		{
			m_bKeyboardBackward = false;
			break;
		}
		case GLFW_KEY_A:
		{
			m_bKeyboardLeft = false;
			m_bKeyboardStrafeLeft = false;
			break;
		}
		case GLFW_KEY_D:
		{
			m_bKeyboardRight = false;
			m_bKeyboardStrafeRight = false;
			break;
		}
		case GLFW_KEY_F:
		{
			m_bKeyboardUp = false;
			break;
		}
		case GLFW_KEY_V:
		{
			m_bKeyboardDown = false;
			break;
		}
		case GLFW_KEY_SPACE:
		{
			m_bKeyboardSpace = false;
			break;
		}
		case GLFW_KEY_ESCAPE:
		{
			m_bKeyboardMenu = false;
			break;
		}
		case GLFW_KEY_O:
		{
			if (STEAM_BUILD == false)
			{
				m_pDebugCameraOptionBox->SetToggled(true);
				CameraModeChanged();
			}
			break;
		}
		case GLFW_KEY_L:
		{
			if (STEAM_BUILD == false)
			{
				SetPaused(!IsPaused());
			}
			break;
		}
		case GLFW_KEY_P:
		{
			if (STEAM_BUILD == false)
			{
				if (m_pGUI->IsKeyboardInteractingWithGUIComponent() == false)
				{
					if (m_pMainWindow->IsVisible() == false)
					{
						ShowGUI();
					}
					else
					{
						HideGUI();
					}
				}
			}
			break;
		}

		// Game GUI
		case GLFW_KEY_I:
		{
			if (GetGameMode() == GameMode_Game)
			{
				if (m_pPlayer->IsDead() == false)
				{
					if (m_pInventoryGUI->IsLoaded())
					{
						m_pInventoryGUI->Unload();

						if (VoxGame::GetInstance()->IsGUIWindowStillDisplayed() == false)
						{
							TurnCursorOff(false);
						}
					}
					else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_None)
					{
						m_pInventoryGUI->Load();

						m_pPlayer->StopMoving();

						TurnCursorOn(false, false);
					}
				}
			}
			break;
		}
		case GLFW_KEY_C:
		{
			if (GetGameMode() == GameMode_Game)
			{
				if (m_pPlayer->IsDead() == false)
				{
					if (m_pCharacterGUI->IsLoaded())
					{
						m_pCharacterGUI->Unload();

						if (VoxGame::GetInstance()->IsGUIWindowStillDisplayed() == false)
						{
							TurnCursorOff(false);
						}
					}
					else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_None)
					{
						m_pCharacterGUI->Load();

						m_pPlayer->StopMoving();

						TurnCursorOn(false, false);
					}
				}
			}
			break;
		}
		case GLFW_KEY_K:
		{
			if (GetGameMode() == GameMode_Game)
			{
				if (m_pPlayer->IsDead() == false)
				{
					if (m_pQuestGUI->IsLoaded())
					{
						m_pQuestGUI->Unload();

						if (VoxGame::GetInstance()->IsGUIWindowStillDisplayed() == false)
						{
							TurnCursorOff(false);
						}
					}
					else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_None)
					{
						m_pQuestGUI->Load();

						m_pPlayer->StopMoving();

						TurnCursorOn(false, false);
					}
				}
			}
			break;
		}

		// Number keys
		case GLFW_KEY_1:
		{
			m_pActionBar->UseActionBarslot(0);
			break;
		}		
		case GLFW_KEY_2:
		{
			m_pActionBar->UseActionBarslot(1);
			break;
		}
		case GLFW_KEY_3:
		{
			m_pActionBar->UseActionBarslot(2);
			break;
		}
		case GLFW_KEY_4:
		{
			m_pActionBar->UseActionBarslot(3);
			break;
		}
		case GLFW_KEY_5:
		{
			m_pActionBar->UseActionBarslot(4);
			break;
		}
		case GLFW_KEY_6:
		{
			m_pActionBar->UseActionBarslot(5);
			break;
		}
		case GLFW_KEY_7:
		{
			m_pActionBar->UseActionBarslot(6);
			break;
		}
		case GLFW_KEY_8:
		{
			m_pActionBar->UseActionBarslot(7);
			break;
		}
		case GLFW_KEY_9:
		{
			m_pActionBar->UseActionBarslot(8);
			break;
		}
		case GLFW_KEY_0:
		{
			m_pActionBar->UseActionBarslot(9);
			break;
		}
	}
}