示例#1
0
//-----------------------------------------------------------------------------------------------------------------------------------
void Camera::Update(DX::StepTimer const& timer)
{
	// If the camera is fixed we should not do any more updating
	if (m_cameraMode == CameraMode::kFixed)
	{
		return;
	}

	KeyboardInput& keyboard = ScreenManager::GetKeyboardInput();
	Vector2 diff = Vector2::Zero;

	if (keyboard.IsKeyDown(Keyboard::Keys::Left))
	{
		diff.x = -1;
	}
	if (keyboard.IsKeyDown(Keyboard::Keys::Right))
	{
		diff.x = 1;
	}
	if (keyboard.IsKeyDown(Keyboard::Keys::Up))
	{
		diff.y = -1;
	}
	if (keyboard.IsKeyDown(Keyboard::Keys::Down))
	{
		diff.y = 1;
	}

	if (diff != Vector2::Zero)
	{
		diff.Normalize();
		m_position += diff * (float)timer.GetElapsedSeconds() * m_panSpeed;
	}
}
示例#2
0
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here.
    elapsedTime;
}
// Called once per frame. Rotates the cube, and calculates and sets the model matrix
// relative to the position transform indicated by hologramPositionTransform.
void SpinningCubeRenderer::Update(const DX::StepTimer& timer)
{
    float const deltaTime = static_cast<float>(timer.GetElapsedSeconds());
    float const lerpDeltaTime = deltaTime * c_lerpRate;

    float3 const prevPosition = m_position;
    m_position = lerp(m_position, m_targetPosition, lerpDeltaTime);

    m_velocity = (prevPosition - m_position) / deltaTime;

    // Rotate the cube.
    // Convert degrees to radians, then convert seconds to rotation angle.
    float const radiansPerSecond = XMConvertToRadians(m_degreesPerSecond);
    float const totalRotation    = static_cast<float>(timer.GetTotalSeconds()) * radiansPerSecond;

    // Scale the cube down to 10cm
    float4x4 const modelScale = make_float4x4_scale({ 0.1f });
    float4x4 const modelRotation = make_float4x4_rotation_y(totalRotation);
    float4x4 const modelTranslation = make_float4x4_translation(m_position);

    m_modelConstantBufferData.model = modelScale * modelRotation * modelTranslation;

    // Use the D3D device context to update Direct3D device-based resources.
    const auto context = m_deviceResources->GetD3DDeviceContext();

    // Update the model transform buffer for the hologram.
    context->UpdateSubresource(
        m_modelConstantBuffer.Get(),
        0,
        nullptr,
        &m_modelConstantBufferData,
        0,
        0
        );
}
示例#4
0
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    float elapsedTime = float(timer.GetElapsedSeconds());
    UNREFERENCED_PARAMETER(elapsedTime);

    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        m_gamePadButtons.Update(pad);

        if (pad.IsViewPressed())
        {
            Windows::ApplicationModel::Core::CoreApplication::Exit();
        }
    }
    else
    {
        m_gamePadButtons.Reset();
    }

    UpdateGame();

    PIXEndEvent();
}
// Updates any time-based rendering resources (currently none).
// This method must be implemented for the Overlay class.
void SampleVirtualControllerRenderer::Update(DX::StepTimer const& timer)
{
    // Update the timers for fading out unused touch inputs.
    float frameTime = static_cast<float>(timer.GetElapsedSeconds());
    if (m_stickFadeTimer > 0)  m_stickFadeTimer -= frameTime;
    if (m_buttonFadeTimer > 0) m_buttonFadeTimer -= frameTime;
}
示例#6
0
//-----------------------------------------------------------------------------------------------------------------------------------
void Button::Update(DX::StepTimer const& timer)
{
	UIObject::Update(timer);

	if (IsActive())
	{
		m_clickResetTimer += (float)timer.GetElapsedSeconds();
		if (m_clickResetTimer >= m_resetTime)
		{
			m_buttonState = ButtonState::kIdle;
		}

		// Lerp our current colour to the default one to create effect when mouse over button
		SetColour(Color::Lerp(GetColour(), m_defaultColour, (float)timer.GetElapsedSeconds() * 3));
	}
}
// Updates the world.
void Sample::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    float elapsedTime = float(timer.GetElapsedSeconds());

    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        m_gamePadButtons.Update(pad);

        if (!m_ui->Update(elapsedTime, pad))
        {
            if (pad.IsViewPressed())
            {
                Windows::ApplicationModel::Core::CoreApplication::Exit();
            }
            if (pad.IsMenuPressed())
            {
                Windows::Xbox::UI::SystemUI::ShowAccountPickerAsync(nullptr,Windows::Xbox::UI::AccountPickerOptions::None);
            }
        }
    }
    else
    {
        m_gamePadButtons.Reset();
    }

    PIXEndEvent();
}
示例#8
0
文件: Game.cpp 项目: ka-s/DTK_test
// Updates the world
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here
    elapsedTime;
    i_render_manager->update();
}
示例#9
0
// Updates the world
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here
    m_screenManager->Update(elapsedTime);
    m_screenManager->HandleInput(elapsedTime);
}
示例#10
0
// Updates the world
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here
	XMMATRIX m = XMMatrixIdentity();
	m = XMMatrixMultiply(m, XMMatrixTranslation(0.0f, 0.0f, 0.0f));
	XMStoreFloat4x4(&m_constantBufferData.model, m);
    elapsedTime;
}
// Updates the world.
void Sample::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    float elapsedTime = float(timer.GetElapsedSeconds());

	// Update the rotation constant
	m_curRotationAngleRad += elapsedTime / 3.f;
	if (m_curRotationAngleRad >= XM_2PI)
	{
		m_curRotationAngleRad -= XM_2PI;
	}

	// Rotate the cube around the origin
	XMStoreFloat4x4(&m_worldMatrix, XMMatrixRotationY(m_curRotationAngleRad));

	// Setup our lighting parameters
	m_lightDirs[0] = XMFLOAT4(-0.577f, 0.577f, -0.577f, 1.0f);
	m_lightDirs[1] = XMFLOAT4(0.0f, 0.0f, -1.0f, 1.0f);

	m_lightColors[0] = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
	m_lightColors[1] = XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f);

	// Rotate the second light around the origin
	XMMATRIX rotate = XMMatrixRotationY(-2.0f * m_curRotationAngleRad);
	XMVECTOR lightDir = XMLoadFloat4(&m_lightDirs[1]);
	lightDir = XMVector3Transform(lightDir, rotate);
	XMStoreFloat4(&m_lightDirs[1], lightDir);

	// Handle controller input for exit
    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        m_gamePadButtons.Update(pad);

        if (pad.IsViewPressed())
        {
            Windows::ApplicationModel::Core::CoreApplication::Exit();
        }
    }
    else
    {
        m_gamePadButtons.Reset();
    }

    auto kb = m_keyboard->GetState();
    m_keyboardButtons.Update(kb);

    if (kb.Escape)
    {
        Windows::ApplicationModel::Core::CoreApplication::Exit();
    }

    PIXEndEvent();
}
void PointLightRenderer::UpdateSpecularLight(const DX::StepTimer& gameTime)
{
	static float specularIntensity = 1.0f;
	GamePad::State gamePadState = mGamePad->CurrentState();
	if (gamePadState.IsConnected())
	{
		if (gamePadState.IsLeftTriggerPressed() && specularIntensity <= 1.0f)
		{
			specularIntensity += static_cast<float>(gameTime.GetElapsedSeconds());
			specularIntensity = min(specularIntensity, 1.0f);

			mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity);
		}

		if (gamePadState.IsRightTriggerPressed() && specularIntensity >= 0.0f)
		{
			specularIntensity -= (float)gameTime.GetElapsedSeconds();
			specularIntensity = max(specularIntensity, 0.0f);

			mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity);
		}

		static float specularPower = mPixelCBufferPerObjectData.SpecularPower;

		if (mGamePad->IsButtonDown(GamePadButton::DPadUp) && specularPower < UCHAR_MAX)
		{
			specularPower += LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds());
			specularPower = min(specularPower, static_cast<float>(UCHAR_MAX));

			mPixelCBufferPerObjectData.SpecularPower = specularPower;
		}

		if (mGamePad->IsButtonDown(GamePadButton::DPadDown) && specularPower > 1.0f)
		{
			specularPower -= LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds());
			specularPower = max(specularPower, 1.0f);

			mPixelCBufferPerObjectData.SpecularPower = specularPower;
		}
	}
}
示例#13
0
//-----------------------------------------------------------------------------------------------------------------------------------
void RigidBody::Update(DX::StepTimer const& timer)
{
	float elapsedSeconds = (float)timer.GetElapsedSeconds();

	// Update the rotation and angular components
	m_angularVelocity += m_angularAcceleration * elapsedSeconds;
	m_parent->SetLocalRotation(m_angularVelocity * elapsedSeconds + m_parent->GetLocalRotation());

	// Update the position and linear components (it IS minus because of the screen coords
	m_linearVelocity += m_linearAcceleration * elapsedSeconds;
	m_parent->SetLocalPosition(m_parent->GetLocalPosition() - Vector2::Transform(m_linearVelocity, Matrix::CreateRotationZ(m_parent->GetLocalRotation())) * elapsedSeconds);
}
示例#14
0
//-----------------------------------------------------------------------------------------------------------------------------------
void UIObject::Update(DX::StepTimer const& timer)
{
	BaseObject::Update(timer);

	m_currentLifeTime += (float)timer.GetElapsedSeconds();
	if (m_currentLifeTime > m_lifeTime)
	{
		// This UIObject has been alive for longer than its lifetime so it dies
		// and will be cleared up by whatever manager is in charge of it
		Die();
	}
}
示例#15
0
文件: Game.cpp 项目: TsubameDono/CCDK
// Updates the world
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here
    elapsedTime;

    for(auto & player: m_players)
    {
        player->Update();
    }
}
示例#16
0
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    Vector3 eye(0.0f, 0.7f, 1.5f);
    Vector3 at(0.0f, -0.1f, 0.0f);

    m_view = Matrix::CreateLookAt(eye, at, Vector3::UnitY);

    m_world = Matrix::CreateRotationY(float(timer.GetTotalSeconds() * XM_PIDIV4));

    m_batchEffect->SetView(m_view);
    m_batchEffect->SetWorld(Matrix::Identity);

#ifdef DXTK_AUDIO
    m_audioTimerAcc -= (float)timer.GetElapsedSeconds();
    if (m_audioTimerAcc < 0)
    {
        if (m_retryDefault)
        {
            m_retryDefault = false;
            if (m_audEngine->Reset())
            {
                // Restart looping audio
                m_effect1->Play(true);
            }
        }
        else
        {
            m_audioTimerAcc = 4.f;

            m_waveBank->Play(m_audioEvent++);

            if (m_audioEvent >= 11)
                m_audioEvent = 0;
        }
    }
#endif

    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        if (pad.IsViewPressed())
        {
            PostQuitMessage(0);
        }
    }

    auto kb = m_keyboard->GetState();
    if (kb.Escape)
    {
        PostQuitMessage(0);
    }
}
void PointLightRenderer::UpdateAmbientLight(const DX::StepTimer& gameTime)
{
	static float ambientIntensity = 0.0f;

	auto gamePadState = mGamePad->CurrentState();
	if (gamePadState.IsConnected())
	{
		if (mGamePad->IsButtonDown(GamePadButton::A) && ambientIntensity <= 1.0f)
		{
			ambientIntensity += static_cast<float>(gameTime.GetElapsedSeconds());
			ambientIntensity = min(ambientIntensity, 1.0f);

			mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f);
		}

		if (mGamePad->IsButtonDown(GamePadButton::B) && ambientIntensity >= 0.0f)
		{
			ambientIntensity -= (float)gameTime.GetElapsedSeconds();
			ambientIntensity = max(ambientIntensity, 0.0f);

			mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f);
		}
	}
}
示例#18
0
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    float elapsedTime = float(timer.GetElapsedSeconds());
    elapsedTime;

    auto pad = m_gamePad->GetState(0);
    auto kb = m_keyboard->GetState();
    if (kb.Escape || (pad.IsConnected() && pad.IsViewPressed()))
    {
        ExitGame();
    }

    PIXEndEvent();
}
示例#19
0
// Called once per frame, updates the scene state.
void Game::Update(DX::StepTimer const& timer)
{
	auto timeDelta = static_cast<float>(timer.GetElapsedSeconds());

	// Update animated models.
	m_skinnedMeshRenderer.UpdateAnimation(timeDelta, m_meshModels);

	// Rotate scene.
	m_rotation = static_cast<float>(timer.GetTotalSeconds()) * 0.5f;

	// Update the "time" variable for the glow effect.
	for (float &time : m_time)
	{
		time = std::max<float>(0.0f, time - timeDelta);
	}
}
// Called once per frame, rotates the cube and calculates the model and view matrices.
void Sample3DSceneRenderer::Update(DX::StepTimer const& timer)
{
	if (m_loadingComplete)
	{
		if (!m_tracking)
		{
			// Rotate the cube a small amount.
			m_angle += static_cast<float>(timer.GetElapsedSeconds()) * m_radiansPerSecond;

			Rotate(m_angle);
		}

		// Update the constant buffer resource.
		UINT8* destination = m_mappedConstantBuffer + (m_deviceResources->GetCurrentFrameIndex() * c_alignedConstantBufferSize);
		memcpy(destination, &m_constantBufferData, sizeof(m_constantBufferData));
	}
}
void DirectXTK3DSceneRenderer::Update(DX::StepTimer const& timer)
{
    Vector3 eye(0.0f, 0.7f, 1.5f);
    Vector3 at(0.0f, -0.1f, 0.0f);

    m_view = Matrix::CreateLookAt(eye, at, Vector3::UnitY);

    m_world = Matrix::CreateRotationY( float(timer.GetTotalSeconds() * XM_PIDIV4) );

    m_batchEffect->SetView(m_view);
    m_batchEffect->SetWorld(Matrix::Identity);

    m_audioTimerAcc -= (float)timer.GetElapsedSeconds();
    if (m_audioTimerAcc < 0)
    {
        if (m_retryDefault)
        {
            m_retryDefault = false;
            if (m_audEngine->Reset())
            {
                // Restart looping audio
                m_effect1->Play(true);
            }
        }
        else
        {
            m_audioTimerAcc = 4.f;

            m_waveBank->Play(m_audioEvent++);

            if (m_audioEvent >= 11)
                m_audioEvent = 0;
        }
    }

    if (!m_audEngine->IsCriticalError() && m_audEngine->Update())
    {
        // Setup a retry in 1 second
        m_audioTimerAcc = 1.f;
        m_retryDefault = true;
    }
}
// Called once per frame. Rotates the cube, and calculates and sets the model matrix
// relative to the position transform indicated by hologramPositionTransform.
void SpinningCubeRenderer::Update(DX::StepTimer const& timer)
{
    constexpr float degreesPerSecond = 45.f;
    constexpr float radiansPerSecond = XMConvertToRadians(degreesPerSecond);

    // Rotate the cube.
    const double yawRadiansDelta = timer.GetElapsedSeconds() * radiansPerSecond;
    m_orientation *= make_quaternion_from_yaw_pitch_roll((float)yawRadiansDelta, 0, 0);

    // Compute updated transform for model.
    const XMMATRIX modelRotation = XMMatrixRotationQuaternion(XMLoadQuaternion(&m_orientation));
    const XMMATRIX modelTranslation = XMMatrixTranslationFromVector(XMLoadFloat3(&m_position));
    const XMMATRIX modelScale = XMMatrixScaling(0.25f, 0.25f, 0.25f);

    // Multiply to get the transform matrix.
    // Note that this transform does not enforce a particular coordinate system. The calling
    // class is responsible for rendering this content in a consistent manner.
    const XMMATRIX modelTransform = XMMatrixMultiply(modelScale, XMMatrixMultiply(modelRotation, modelTranslation));

    // The view and projection matrices are provided by the system; they are associated
    // with holographic cameras, and updated on a per-camera basis.
    // Here, we provide the model transform for the sample hologram.
    m_cubeModel->GetNode(Pbr::RootNodeIndex).SetTransform(modelTransform);
}
void PointLightRenderer::UpdatePointLight(const DX::StepTimer& gameTime)
{
 	static float pointLightIntensity = 1.0f;
	float elapsedTime = static_cast<float>(gameTime.GetElapsedSeconds());
 
	GamePad::State gamePadState = mGamePad->CurrentState();
	if (gamePadState.IsConnected())
	{
		// Update point light intensity		
		if (mGamePad->IsButtonDown(GamePadButton::X) && pointLightIntensity <= 1.0f)
		{
			pointLightIntensity += elapsedTime;
			pointLightIntensity = min(pointLightIntensity, 1.0f);

			mPixelCBufferPerFrameData.LightColor = XMFLOAT4(pointLightIntensity, pointLightIntensity, pointLightIntensity, 1.0f);
			mPointLight->SetColor(mPixelCBufferPerFrameData.LightColor);
		}
		if (mGamePad->IsButtonDown(GamePadButton::Y) && pointLightIntensity >= 0.0f)
		{
			pointLightIntensity -= elapsedTime;
			pointLightIntensity = max(pointLightIntensity, 0.0f);

			mPixelCBufferPerFrameData.LightColor = XMFLOAT4(pointLightIntensity, pointLightIntensity, pointLightIntensity, 1.0f);
			mPointLight->SetColor(mPixelCBufferPerFrameData.LightColor);
		}

		// Move point light
		XMFLOAT3 movementAmount = Vector3Helper::Zero;
		if (!bIsCameraControlled)
		{
			if (gamePadState.IsLeftThumbStickLeft())
			{
				movementAmount.x = -1.0f;
			}

			if (gamePadState.IsLeftThumbStickRight())
			{
				movementAmount.x = 1.0f;
			}

			if (gamePadState.IsLeftThumbStickUp())
			{
				movementAmount.y = 1.0f;
			}

			if (gamePadState.IsLeftThumbStickDown())
			{
				movementAmount.y = -1.0f;
			}

			if (gamePadState.IsRightThumbStickLeft())
			{
				movementAmount.z = -1.0f;
			}

			if (gamePadState.IsRightThumbStickRight())
			{
				movementAmount.z = 1.0f;
			}
		}
		XMVECTOR movement = XMLoadFloat3(&movementAmount) * LightMovementRate * elapsedTime;
		mPointLight->SetPosition(mPointLight->PositionVector() + movement);
		mProxyModel->SetPosition(mPointLight->Position());
		mVertexCBufferPerFrameData.LightPosition = mPointLight->Position();

		mPixelCBufferPerFrameData.LightPosition = mPointLight->Position();
	}

}
示例#24
0
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    Vector3 eye(0.0f, 0.7f, 1.5f);
    Vector3 at(0.0f, -0.1f, 0.0f);

    m_view = Matrix::CreateLookAt(eye, at, Vector3::UnitY);

    m_world = Matrix::CreateRotationY(float(timer.GetTotalSeconds() * XM_PIDIV4));

    m_lineEffect->SetView(m_view);
    m_lineEffect->SetWorld(Matrix::Identity);

    m_shapeEffect->SetView(m_view);

    m_audioTimerAcc -= (float)timer.GetElapsedSeconds();
    if (m_audioTimerAcc < 0)
    {
        if (m_retryDefault)
        {
            m_retryDefault = false;
            if (m_audEngine->Reset())
            {
                // Restart looping audio
                m_effect1->Play(true);
            }
        }
        else
        {
            m_audioTimerAcc = 4.f;

            m_waveBank->Play(m_audioEvent++);

            if (m_audioEvent >= 11)
                m_audioEvent = 0;
        }
    }

    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        m_gamePadButtons.Update(pad);

        if (pad.IsViewPressed())
        {
            PostQuitMessage(0);
        }
    }
    else
    {
        m_gamePadButtons.Reset();
    }

    auto kb = m_keyboard->GetState();
    m_keyboardButtons.Update(kb);

    if (kb.Escape)
    {
        PostQuitMessage(0);
    }

    auto mouse = m_mouse->GetState();
    mouse;

    PIXEndEvent();
}
示例#25
0
// Updates the world.
void Sample::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    if (m_isProtocolActivated &&
        m_liveResources->GetUser() != nullptr && m_liveResources->GetUser()->IsSignedIn)
    {
        HandleProtocolActivation();
    }

    float elapsedTime = float(timer.GetElapsedSeconds());
    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        m_gamePadButtons.Update(pad);

        if (!m_ui->Update(elapsedTime, pad))
        {
            if (m_clearErrorMsgTimer > 0.0f)
            {
                m_clearErrorMsgTimer -= elapsedTime;
                if (m_clearErrorMsgTimer < 0.0f)
                {
                    m_clearErrorMsgTimer = 0.0f;
                    m_errorMsgConsole->Clear();
                }
            }

            if (m_appState == APPSTATE::APP_MAIN_MENU)
            {
                if (pad.IsMenuPressed())
                {
                    Windows::Xbox::UI::SystemUI::ShowAccountPickerAsync(nullptr, Windows::Xbox::UI::AccountPickerOptions::None);
                }
            }
            else if (m_appState == APPSTATE::APP_IN_GAME)
            {
                if (m_gamePadButtons.dpadRight == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    PublishSearchHandle();
                }

                if (m_gamePadButtons.dpadLeft == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    BrowseSearchHandles();
                }

                if (m_gamePadButtons.leftTrigger == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    UpdateLobbyProperties();
                }

                if (m_gamePadButtons.rightTrigger == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    SetLobbyHost();
                }

                if (m_gamePadButtons.leftShoulder == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    UpdateGameProperties();
                }

                if (m_gamePadButtons.rightShoulder == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    SetGameHost();
                }

                if (m_gamePadButtons.a == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    JoinGameFromLobby();
                }

                if (m_gamePadButtons.b == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    if (m_multiplayerManager->game_session() != nullptr)
                    {
                        LeaveGameSession();
                    }
                    else
                    {
                        RemoveLocalUser();
                    }
                }

                if (m_gamePadButtons.x == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    InviteFriends();
                }

                if (m_gamePadButtons.y == GamePad::ButtonStateTracker::ButtonState::PRESSED)
                {
                    UpdateJoinability();
                }
            }
        }
    }
    else
    {
        m_gamePadButtons.Reset();
    }

    PIXBeginEvent(PIX_COLOR_DEFAULT, L"MPM::DoWork");
    DoWork();
    PIXEndEvent();
    PIXEndEvent();
}
// Updates the scene to be displayed.
void DirectXTK3DSceneRenderer::Update(DX::StepTimer const& timer, std::vector<PlayerInputData>* playerInputs, unsigned int playersAttached)
{
	m_audioTimerAcc -= (float)timer.GetElapsedSeconds();
	if (m_audioTimerAcc < 0)
	{
		if (m_retryDefault)
		{
			m_retryDefault = false;
			if (m_audEngine->Reset())
			{
				// Restart looping audio
				m_effect1->Play(true);
			}
		}
		else
		{
			m_audioTimerAcc = 4.f;
			m_waveBank->Play(m_audioEvent++);
			if (m_audioEvent >= 11)
				m_audioEvent = 0;
		}
	}

	if (!m_audEngine->IsCriticalError() && m_audEngine->Update())
	{
		// Setup a retry in 1 second
		m_audioTimerAcc = 1.f;
		m_retryDefault = true;
	}

	if (screenManager->win())
	{
		screenManager->loadNextLevel();
		//screenManager->setString(L"GameOver", L"ScoreGameOver", std::to_wstring(screenManager->game->getScore()));
		//screenManager->setName(L"GameOver");
	}
	if (screenManager->gameOver())
	{
		screenManager->setString(L"GameOver", L"ScoreGameOver", L"Score: "  + std::to_wstring(screenManager->game->getScore()));
		screenManager->setName(L"GameOver");
	}
	
	//#pragma region Gamepad
	//	//GamePad
	//	auto statePlayerOne = GameePad->GetState(0);
	//	if (statePlayerOne.IsConnected())
	//	{
	//		XMFLOAT2 tempPos = player->getPosition();
	//		if (statePlayerOne.IsDPadUpPressed()){
	//			tempPos.y -= 10; //CHANGE TO PROPER OFFSET CALCULATION - USING TIME 
	//		}
	//
	//		if (statePlayerOne.IsDPadDownPressed()){
	//			tempPos.y += 10; ////CHANGE TO PROPER OFFSET CALCULATION - USING TIME 
	//		}
	//		
	//		if (statePlayerOne.IsDPadLeftPressed()){
	//			tempPos.x -= 10; //CHANGE TO PROPER OFFSET CALCULATION - USING TIME 
	//		}
	//		if (statePlayerOne.IsDPadRightPressed()){
	//			tempPos.x += 10; //CHANGE TO PROPER OFFSET CALCULATION - USING TIME 	
	//		}
	//		player->setPosition(tempPos);	
	//	}
	//#pragma endregion Handling the Enginepad Input

	//auto test = timer.GetElapsedSeconds();

	//update the animation
	//animation->Update((float)timer.GetElapsedSeconds());
	//player->Update((float)timer.GetElapsedSeconds());

//#pragma region Enemy AI
	// TODO: handle enemy AI using promises and Lambdas
	//std::vector<std::future<DirectX::XMFLOAT2>> futures;
	//for (auto enemy : enemiesVector)
	//{
	//	futures.push_back( std::async(std::launch::async,
	//		[]()
	//	{
	//		DirectX::XMFLOAT2 tempPos;
	//		//TODO: Write code for very complicated AI here
	//		return tempPos;
	//	}) );
	//}

	//for (auto &future : futures)
	//{
		//TODO:get results
		//auto enemiesIterator = enemiesVector.begin();

	//	DirectX::XMFLOAT2 tempPos;
	//	tempPos = future.get();
		//(*enemiesIterator).setPosition(tempPos);
		//enemiesIterator++;
	//}
//#pragma endregion Handling Enemy AI using std::async and std::Future. Also using C++11 Lambdas

//#pragma region Collisions
	//collisionString = L"There is no collision";
	//EnginePad->SetVibration(0, 0.f, 0.f);
	/*for (auto wallsIterator = wallsVector.begin(); wallsIterator < wallsVector.end(); wallsIterator++)
	{

	(*wallsIterator).Update((float)timer.GetElapsedSeconds());
	if ((*wallsIterator).isCollidingWith(player->rectangle)){
	collisionString = L"There is a collision with the wall";

	EnginePad->SetVibration(0, 0.75f, 0.75f);
	}
	}*/
	screenManager->Update((float)timer.GetElapsedSeconds());

//#pragma endregion Handling collision detection + simple EnginePad rumble on crash

	m_playersAttached = playersAttached;

	for (unsigned int i = 0; i < XINPUT_MAX_CONTROLLERS; i++)
	{
		unsigned int playerAttached = (playersAttached & (1 << i));

		if (!playerAttached)
			continue;

		for (unsigned int j = 0; j < playerInputs->size(); j++)
		{
			PlayerInputData playerAction = (*playerInputs)[j];

			if (playerAction.ID != i) continue;
			switch (playerAction.PlayerAction)
			{
			case PLAYER_ACTION_TYPES::INPUT_FIRE_PRESSED:
				break;
			case PLAYER_ACTION_TYPES::INPUT_FIRE_DOWN:
				if (flagFromPressToRelasedClick)
				{
					if (screenManager->getName() == L"Play")
					{
						screenManager->game->fire();
					}
					if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"StartMain"))
					{
						screenManager->setName(L"Level");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"OptionsMain"))
					{
						screenManager->setName(L"Options");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"ExitMain"))
					{
						//TO DO: exit
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"MusicOptions"))
					{
						m_playMusic = !m_playMusic;
						if (m_playMusic)
						{
							m_effect1->Play(true);
							m_effect2->Play();
							screenManager->setString(L"Options", L"MusicOptions", L"Music: on");
						}
						else
						{
							m_effect1->Pause();
							m_effect2->Pause();
							screenManager->setString(L"Options", L"MusicOptions", L"Music: off");
						}
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"AuthorOptions"))
					{
						screenManager->setName(L"Author");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"BackOptions"))
					{
						screenManager->setName(L"Main");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"SingleplayerLevel"))
					{
						screenManager->resetLevel();
						screenManager->loadLevel(L"1");
						screenManager->setName(L"Play");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"BackLevel"))
					{
						screenManager->setName(L"Main");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"PausePlay"))
					{
						screenManager->setName(L"Pause");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"ReturnPause"))
					{
						screenManager->setName(L"Play");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"ExitPause"))
					{
						screenManager->setName(L"Main");
						screenManager->resetLevel();
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"DescriptionAuthor"))
					{
						screenManager->resetLevel();
						screenManager->loadLevel(L"Secret");
						screenManager->setName(L"Play");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"BackAuthor"))
					{
						screenManager->setName(L"Options");
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"ContinueGameOver"))
					{
						screenManager->setName(L"Main");
						screenManager->resetLevel();
					}
					else if (screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY) == (L"RestartPause"))
					{
						screenManager->setName(L"Play");
						screenManager->game->resetLevel();
					}
					flagFromPressToRelasedClick = false;
				}
				break;
			case PLAYER_ACTION_TYPES::INPUT_CANCEL:
				break;
			case PLAYER_ACTION_TYPES::INPUT_FIRE_RELEASED:
				flagFromPressToRelasedClick = true;
				break;

			case PLAYER_ACTION_TYPES::INPUT_JUMP_PRESSED:
				break;
			case PLAYER_ACTION_TYPES::INPUT_JUMP_DOWN:
				break;
			case PLAYER_ACTION_TYPES::INPUT_JUMP_RELEASED:
				break;

			case PLAYER_ACTION_TYPES::INPUT_MOVE:
				screenManager->game->player->move(playerAction.X, playerAction.Y);
				if (playerAction.Y == 1)
					screenManager->game->player->jump();
				break;
			case PLAYER_ACTION_TYPES::INPUT_AIM:
				break;
			case PLAYER_ACTION_TYPES::INPUT_BRAKE:
				break;

			default:
				screenManager->isClicked(playerAction.PointerRawX, playerAction.PointerRawY);
				break;
			}
		}

		wchar_t intStringBuffer[8];
		size_t sizeInWords = sizeof(intStringBuffer) / 2;
		_itow_s(i + 1, intStringBuffer, sizeInWords, 10);
		std::wstring playerIdString(intStringBuffer);

		//m_text[i] = L"Input Player" + playerIdString += L": " + inputText;

		/*DX::ThrowIfFailed(
		m_deviceResources->GetDWriteFactory()->CreateTextLayout(
		m_text[i].c_str(),
		(uint32)m_text[i].length(),
		m_textFormat.Get(),
		DEBUG_INPUT_TEXT_MAX_WIDTH,
		DEBUG_INPUT_TEXT_MAX_HEIGHT,
		&m_textLayout[i]
		)
		);
		DX::ThrowIfFailed(
		m_textLayout[i]->GetMetrics(&m_textMetrics[i])
		);*/
	}
}
// Called once per frame
void Sample3DSceneRenderer::Update(DX::StepTimer const& timer)
{
	//if (!m_tracking)
	//{
	//	// Convert degrees to radians, then convert seconds to rotation angle
	//	float radiansPerSecond = XMConvertToRadians(m_degreesPerSecond);
	//	double totalRotation = timer.GetTotalSeconds() * radiansPerSecond;
	//	float radians = static_cast<float>(fmod(totalRotation, XM_2PI));

	//	Rotate(radians);
	//}

	//m_audioTimerAcc -= (float)timer.GetElapsedSeconds();
	//if (m_audioTimerAcc < 0)
	//{
	//	if (m_retryDefault)
	//	{
	//		m_retryDefault = false;
	//		if (m_audEngine->Reset())
	//		{
	//			// Restart looping audio
	//			m_effect1->Play(true);
	//		}
	//	}
	//	else
	//	{
	//		m_audioTimerAcc = 4.f;

	//		m_waveBank->Play(m_audioEvent++);

	//		if (m_audioEvent >= 11)
	//			m_audioEvent = 0;
	//	}
	//}

	//if (!m_audEngine->IsCriticalError() && m_audEngine->Update())
	//{
	//	// Setup a retry in 1 second
	//	m_audioTimerAcc = 1.f;
	//	m_retryDefault = true;
	//}
	auto windowSize = m_deviceResources->GetOutputSize(); // physical screen resolution
	auto logicalSize = m_deviceResources->GetLogicalSize(); //DPI dependent resolution



#pragma region Handling Adding Enemies

	//Enemy enemyTemp(enemyTexture.Get());
	//enemiesVector.push_back(enemyTemp);

	if (enemiesVector.size() < 5)
	{
		std::random_device rd;
		std::default_random_engine random(rd());

		std::uniform_int_distribution<int> dist(0, (int)windowSize.Height); //Choose distribution of the result (inclusive,inclusive)
		std::uniform_int_distribution<int> dist2(5, 25); //Choose distribution of the result (inclusive,inclusive)

		Enemy enemyTemp(enemyTexture.Get());
		XMFLOAT2 tempPos{ 0,0 };
		tempPos.x = windowSize.Width;
		tempPos.y = dist(random);
		enemyTemp.setFlightSpeed(dist2(random));
		enemyTemp.setPosition(tempPos);
		enemiesVector.push_back(enemyTemp);
	}

#pragma endregion


#pragma region Gamepad
	//GamePad
	auto statePlayerOne = gamePad->GetState(0);
	if (statePlayerOne.IsConnected())
	{
		XMFLOAT2 tempPos = player->getPosition();
		if (statePlayerOne.IsDPadUpPressed()) {
			tempPos.y -= 10; //CHANGE TO PROPER OFFSET CALCULATION - USING TIME 
		}

		if (statePlayerOne.IsDPadDownPressed()) {
			tempPos.y += 10; ////CHANGE TO PROPER OFFSET CALCULATION - USING TIME 
		}

		if (statePlayerOne.IsDPadLeftPressed()) {
			tempPos.x -= 10; //CHANGE TO PROPER OFFSET CALCULATION - USING TIME 
		}
		if (statePlayerOne.IsDPadRightPressed()) {
			tempPos.x += 10; //CHANGE TO PROPER OFFSET CALCULATION - USING TIME 	
		}
		player->setPosition(tempPos);
	}
#pragma endregion Handling the Gamepad Input


#pragma region Keyboard
	std::unique_ptr<Keyboard::KeyboardStateTracker> tracker(new Keyboard::KeyboardStateTracker);



	auto keyboardState = Keyboard::Get().GetState();

	tracker->Update(keyboardState);
	XMFLOAT2 tempPos = player->getPosition();
	if (tracker->pressed.S)
	{

		tempPos.y += 10;
	}

	if (tracker->pressed.W)
	{

		tempPos.y -= 10;
	}

	if (tracker->pressed.A)
	{
		tempPos.x -= 10;
	}
	if (tracker->pressed.D)
	{
		tempPos.x += 10;
	}


	player->setPosition(tempPos);


#pragma endregion Handling Keyboard input




#pragma region Paralaxing background
	//Update Background
	background->Update((float)timer.GetElapsedSeconds() * 100);
	clouds->Update((float)timer.GetElapsedSeconds() * 300);
	clouds2->Update((float)timer.GetElapsedSeconds() * 900);
#pragma endregion Handling the paralaxing backgrounds

	//auto test = timer.GetElapsedSeconds();


	//update the animation
	//animation->Update((float)timer.GetElapsedSeconds());
	player->Update((float)timer.GetElapsedSeconds());



#pragma	region Updating Enemies without AI
	for (auto & enemy : enemiesVector)
	{
		
		XMFLOAT2 tempPos = enemy.getPosition();
		tempPos.x -= enemy.getFlightSpeed(); //CHANGE TO PROPER POSITIONING USING TIME
		enemy.setPosition(tempPos);
		if (tempPos.x < 0)
		{
			enemy.setVisibility(false);
		}

	}

#pragma endregion



#pragma region Updating Enemies with AI
	// TODO: handle enemy AI using promises and Lambdas
	std::vector<std::future<DirectX::XMFLOAT2>> futures;

	for (auto& enemy : enemiesVector)
	{
		futures.push_back(std::async(std::launch::async,
			[&]()
		{
			
			Enemy & currentEnemy = enemy;
			DirectX::XMFLOAT2 enemyPos{ 0,0 };
			DirectX::XMFLOAT2 playerPos = player->getPosition();
			//TODO: Write code for very complicated AI here

			return enemyPos;

		}));
	}

	for (auto &future : futures)
	{
		//TODO:get results

		auto enemiesIterator = enemiesVector.begin();

		DirectX::XMFLOAT2 tempPos;
		tempPos = future.get();
		//(*enemiesIterator).setPosition(tempPos);
		//enemiesIterator++;
	}

#pragma endregion Handling Enemy AI using std::async and std::Future. Also using C++11 Lambdas




#pragma region Collisions
	collisionString = L"There is no collision";
	gamePad->SetVibration(0, 0.f, 0.f);
	
	// Collisions of Player with walls
	for (auto wallsIterator = wallsVector.begin(); wallsIterator < wallsVector.end(); wallsIterator++)
	{

		(*wallsIterator).Update((float)timer.GetElapsedSeconds());
		if ((*wallsIterator).isCollidingWith(player->rectangle)) {
			collisionString = L"There is a collision with the wall";

			gamePad->SetVibration(0, 0.75f, 0.75f);
		}
	}

	//Collisions of Enemies with Player

	for (auto &enemy : enemiesVector)
	{
		if (enemy.isCollidingWith(player->rectangle))
		{
			enemy.setVisibility (false);
		}

	}


	//Collisions with Enemies with Walls




#pragma endregion Handling collision detection + simple GamePad rumble on crash
	
#pragma region	Final update for enemies

	for (auto it = enemiesVector.begin(); it < enemiesVector.end();)
	{
		if (it->isVisible() == false)
		{
			it = enemiesVector.erase(it);
		}
		else
		{
			it->Update((float)timer.GetElapsedSeconds());
			it++;
		}

	}
#pragma endregion




}
示例#28
0
文件: Game.cpp 项目: and0p/NesVoxel
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());
    elapsedTime;
}
示例#29
0
//-----------------------------------------------------------------------------------------------------------------------------------
void Script::Run(DX::StepTimer const& timer)
{
	m_running = true;
	m_timeRunFor += static_cast<float>(timer.GetElapsedSeconds());
}