Esempio n. 1
0
void Camera::Update(GameTime gameTime)
{
	// Check for movement of the camera.
	if(GetAsyncKeyState('Q'))
		MoveLeft(gameTime);
	else if(GetAsyncKeyState('E'))
		MoveRight(gameTime);

	if(GetAsyncKeyState('W'))
		MoveForward(gameTime);
	else if(GetAsyncKeyState('S'))
		MoveBack(gameTime);

	if(GetAsyncKeyState('A'))
		TurnHorizontal((float)(-gameTime.GetTimeSinceLastTick().Milliseconds) * C_TILTING_SPEED);
	else if(GetAsyncKeyState('D'))
		TurnHorizontal((float)gameTime.GetTimeSinceLastTick().Milliseconds * C_TILTING_SPEED);

	// Check for tilting of camera.
	//if(GetAsyncKeyState(VK_LBUTTON))
	//{
	//	float dx = prevInput.Mouse.x - currInput.Mouse.x;
	//	float dy = prevInput.Mouse.y - currInput.Mouse.y;
	//	//TurnHorizontal(dx * C_TILTING_SPEED);
	//	//TurnVertical(dy * C_TILTING_SPEED);
	//}
}
Esempio n. 2
0
// Move camera forwards: walk
void Camera::MoveForward(GameTime& gameTime)
{
	D3DXVECTOR3 forward;

	forward = mDirection - (D3DXVec3Dot(&mDirection, &mWorldUp) * mWorldUp);
	D3DXVec3Normalize(&forward, &forward);
	mPosition += forward * C_MOVE_SPEED * (float)gameTime.GetTimeSinceLastTick().Seconds;
}
Esempio n. 3
0
void Camera::Update(const InputState& prevInput, const InputState& currInput, const GameTime& gameTime)
{
	D3DXVECTOR3 displacement = mDestination - mPosition;
	//D3DXVec3Normalize(&displacement, &displacement);

	mPosition += displacement * gameTime.GetTimeSinceLastTick().Seconds;
	
	displacement = mDestination - mPosition;
	if (D3DXVec3Length(&displacement) <= 1.0f)
	{
		mPosition = mDestination;
	}
}
Esempio n. 4
0
// Tilt the camera horisontally: look left/right
void Camera::TurnHorizontal(const GameTime& gameTime, bool turnLeft)
{
	float angle = (float)gameTime.GetTimeSinceLastTick().Milliseconds * C_TILTING_SPEED;
	if(turnLeft)
		angle = -angle;

	D3DXVECTOR3 up;
	D3DXVec3Cross(&up, &mDirection, &GetRight());
	D3DXMATRIX rotation;

	D3DXMatrixRotationAxis(&rotation, &up, angle);
	D3DXVec3TransformCoord(&mDirection, &mDirection, &rotation);
	D3DXVec3Normalize(&mDirection, &mDirection);
}
Esempio n. 5
0
// Move camera to the right: strafe
void Camera::MoveRight(GameTime& gameTime)
{
	D3DXVECTOR3 right = GetRight();
	mPosition += right * C_MOVE_SPEED * (float)gameTime.GetTimeSinceLastTick().Seconds;
}
Esempio n. 6
0
	void ServerSession::Update(const GameTime& gameTime)
	{
		// Update the server
		mServer->Update();
		
		// Handle all messages
		Network::SlotMessage message;
		while ((message = mServer->PopMessage()).mMessage != NULL)
		{
			// Get the player this message is about
			//PlayerID slot = GetPlayerID(message.mSlot);

			// If we've received a message, update timeout (unless they're marked to be removed)
			if (std::find(mClientsToRemove.begin(), mClientsToRemove.end(), message.mSlot) == mClientsToRemove.end())
			{
				mClientTimeout[message.mSlot] = C_TIMEOUT;
			}

			// Parse the message content
			switch (message.mMessage->ID())
			{
				case Network::C_MESSAGE_CHAT:
				{
					Network::ChatMessage* m = static_cast<Network::ChatMessage*>(message.mMessage);

					HandleChatMessage(m->mSourceID, m->mTargetID, m->mRecipient, m->mMessage);
				} break;

				case Network::C_MESSAGE_JOIN:
				{
					Network::JoinMessage* m = static_cast<Network::JoinMessage*>(message.mMessage);
				
					HandleJoinMessage(message.mSlot, m->mName);
				} break;
				
				case Network::C_MESSAGE_LEAVE_GAME:
				{
					Network::LeaveGameMessage* m = static_cast<Network::LeaveGameMessage*>(message.mMessage);

					// Do we need this? Notice this on timeout instead?
				} break;

				case Network::C_MESSAGE_PLACE_PIECE:
				{
					Network::PlacePieceMessage* m = static_cast<Network::PlacePieceMessage*>(message.mMessage);

					// If the move is valid, add the marker and move to the next player
					if (mGrid.GetMarkerInCell(m->mX, m->mY) == C_PLAYER_NONE)
					{
						if (mCurrentPlayer == m->mPlayerID)
						{
							mGrid.AddMarker(Logic::Cell(m->mX, m->mY), m->mPlayerID);
							if (mSessionNotifiee != NULL)
								mSessionNotifiee->PlacePiece(m->mPlayerID, Logic::Cell(m->mX, m->mY));

							mServer->Send(Network::PlacePieceMessage(m->mPlayerID, m->mX, m->mY, -1));

							if (!CheckAndHandleWin())
							{
								mCurrentPlayer = mRuleset->GetNextPlayer(mCurrentPlayer);
							}
						}
					}
					
					mServer->Send(Network::TurnMessage(mCurrentPlayer));
				} break;

				case Network::C_MESSAGE_SET_TEAM:
				{
					Network::SetTeamMessage* m = static_cast<Network::SetTeamMessage*>(message.mMessage);

					assert(mPlayers[m->mPlayerID] != NULL);
					assert(m->mTeam >= C_TEAM_NONE);
					assert(m->mTeam < 2);

					if (GetPlayerSlot(message.mSlot) == m->mPlayerID)
					{
						mPlayers[m->mPlayerID]->SetTeam(m->mTeam);

						if (mSessionNotifiee != NULL)
							mSessionNotifiee->SetTeam(m->mPlayerID, m->mTeam);

						mServer->Send(Network::SetTeamMessage(m->mPlayerID, m->mTeam));
					}
				} break;

				case Network::C_MESSAGE_HIGHLIGHT:
				{
					Network::HighlightMessage* m = static_cast<Network::HighlightMessage*>(message.mMessage);
					PlayerID source = GetPlayerSlot(message.mSlot);

					for (PlayerID s = 0; s < mPlayers.size(); ++s)
					{
						if (mPlayers[s]->GetTeam() == mPlayers[source]->GetTeam() && s != source)
						{
							if (mPlayerClients[s] >= 0)
							{
								// Remote
								mServer->Send(Network::HighlightMessage(m->mX, m->mY, m->mType));
							}
							else
							{
								// Local
								if (mSessionNotifiee != NULL)
									mSessionNotifiee->SetHighlightedCell(Logic::Cell(m->mX, m->mY), m->mType);
							}
						}
					}
				} break;
			}

			SafeDelete(message.mMessage);
		}

		// Decrease timeout
		float dt = gameTime.GetTimeSinceLastTick().Seconds;
		for (TimeoutMap::iterator it = mClientTimeout.begin(); it != mClientTimeout.end(); it++)
		{
			it->second -= dt;
			if (it->second <= 0.0f && mServer->IsConnected(it->first))
			{
				// TODO: Enable timeout again
				mServer->DisconnectClient(it->first);
			}
		}
	}
Esempio n. 7
0
// Move camera to the left: strafe
void Camera::MoveLeft(const GameTime& gameTime)
{
	D3DXVECTOR3 right = GetRight();
	mPosition -= right * C_MOVE_SPEED * (float)gameTime.GetTimeSinceLastTick().Seconds;
	mDestination = mPosition;
}