示例#1
0
//----------------------------------------------------------------------------
void Player::ProcessInput()
{
	Application* pApplication = Application::GetApplication();
	InputSystem* pInputSystem = pApplication->GetInputSystem();
	if (!pInputSystem)
	{
		return;
	}

	if (pInputSystem->GetMainDevicesCount() == 0)
	{
		return;
	}

	const MainInputDevice* pInputDevice = pInputSystem->GetMainDevice(0);

	// Checking minimum capabilities
	if (!pInputDevice->HasCapability(AnalogPad::TYPE, true) && !pInputDevice->
		HasCapability(DigitalPad::TYPE, true))
	{
		return;
	}

	if (!pInputDevice->HasCapability(IR::TYPE, true))
	{
		return;
	}

	if (!pInputDevice->HasCapability(Buttons::TYPE, true))
	{
		return;
	}

	// Processing analog/digital pad
	//
	if (pInputDevice->HasCapability(AnalogPad::TYPE, true))
	{
		const AnalogPad* pAnalogPad = DynamicCast<const AnalogPad>(pInputDevice->
			GetCapability(AnalogPad::TYPE, true));
		WIRE_ASSERT(pAnalogPad);

		if (pAnalogPad->GetUp() > 0)
		{
			MoveForward();
		}
		else if (pAnalogPad->GetDown() > 0)
		{
			MoveBackward();
		}

		if (pAnalogPad->GetRight() > 0)
		{
			StrafeRight();
		}
		else if (pAnalogPad->GetLeft() > 0)
		{
			StrafeLeft();
		}
	}
	else 
	{
		const DigitalPad* pDigitalPad = DynamicCast<const DigitalPad>(pInputDevice->
			GetCapability(DigitalPad::TYPE, false));
		WIRE_ASSERT(pDigitalPad);

		if (pDigitalPad->GetUp())
		{
			MoveForward();
		}
		else if (pDigitalPad->GetDown())
		{
			MoveBackward();
		}

		if (pDigitalPad->GetLeft())
		{
			StrafeLeft();
		}
		else if (pDigitalPad->GetRight())
		{
			StrafeRight();
		}
	}

	// Processing buttons
	//
	const Buttons* pButtons = DynamicCast<const Buttons>(pInputDevice->
		GetCapability(Buttons::TYPE, false));
	WIRE_ASSERT(pButtons);

	// 'A' button makes the player shoot
	if (pButtons->GetButton(Buttons::BUTTON_A))
	{
		if (mpGun && mpGun->Culling == Spatial::CULL_DYNAMIC)
		{
			ShootGun();
		}
	}

	// 'B' button makes the player jump
	if (pButtons->GetButton(Buttons::BUTTON_B))
	{
		Jump();
	}

	// If there's a nunchuk, start reading its buttons instead
	if (pInputDevice->HasExtension(Nunchuk::TYPE))
	{
		pButtons = DynamicCast<const Buttons>(pInputDevice->GetExtension(Nunchuk::TYPE)->
			GetCapability(Buttons::TYPE));
		WIRE_ASSERT(pButtons);
	}

	// 'Z' button makes the player run
	if (pButtons->GetButton(Buttons::BUTTON_Z))
	{
		SetMoveSpeed(8.0F);
	}
	else
	{
		SetMoveSpeed(4.0F);
	}

	// get the main device tilt (win32: mouse wheel) (in degrees)
	const Tilt* pTilt = DynamicCast<const Tilt>(pInputDevice->
		GetCapability(Tilt::TYPE, false));
	if (pTilt)
	{
		Float tilt = MathF::DEG_TO_RAD * (pTilt->GetLeft());
		if (mRolls.GetQuantity() == mRolls.GetMaxQuantity())
		{
			for (UInt i = 1; i < mRolls.GetQuantity(); i++)
			{
				mRolls[i-1] = mRolls[i];
			}

			mRolls[mRolls.GetQuantity()-1] = tilt;
		}
		else
		{
			mRolls.Append(tilt);
		}
	}
}