public void ProcessInput(GameTime gameTime, InputInformation inputInfo) { // Is it time to send outgoing network packets? bool sendPacketThisFrame = false; framesSinceLastSend++; if (framesSinceLastSend >= Application.CLIENT_UPDATE_RATE) { sendPacketThisFrame = true; framesSinceLastSend = 0; } // Process and fetch input from local player KeyboardMovementInput condensedInput = ProcessInputForLocalPlayer(gameTime, inputInfo); // Build an update packet from the input and player values PlayerUpdatePacket packet = _localPlayer.BuildUpdatePacket(); packet.DeltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; packet.Input = condensedInput; packet.SequenceNumber = _packetNumber++; // Add it to the queue _updatePackets.Enqueue(packet); if (sendPacketThisFrame) { // Send the packet to the server SendMessageToTheServer(packet, MessageType.GI_ClientSend_PlayerUpdate); } }
public void ProcessInput(GameTime gameTime, InputInformation inputInfo) { if (_currentScene == null) { return; } _currentScene.ProcessInput(gameTime, inputInfo); }
public void ProcessInput(GameTime gameTime, InputInformation inputInfo) { if (_waitingForResponseFromServer) { return; } CheckBottomButtonClicked(inputInfo); CheckRoomClicked(inputInfo); }
private KeyboardMovementInput ProcessInputForLocalPlayer(GameTime gameTime, InputInformation inputInfo) { KeyboardMovementInput input = new KeyboardMovementInput(); // Keyboard/Dpad controls if (inputInfo.CurrentKeyboardState.IsKeyDown(Keys.Left) || inputInfo.CurrentGamePadState.DPad.Left == ButtonState.Pressed) { input.LeftPressed = true; } if (inputInfo.CurrentKeyboardState.IsKeyDown(Keys.Right) || inputInfo.CurrentGamePadState.DPad.Right == ButtonState.Pressed) { input.RightPressed = true; } if (inputInfo.CurrentKeyboardState.IsKeyDown(Keys.Up) || inputInfo.CurrentGamePadState.DPad.Up == ButtonState.Pressed) { input.UpPressed = true; } if (inputInfo.CurrentKeyboardState.IsKeyDown(Keys.Down) || inputInfo.CurrentGamePadState.DPad.Down == ButtonState.Pressed) { input.DownPressed = true; } if (inputInfo.CurrentKeyboardState.IsKeyDown(Keys.Space) || inputInfo.CurrentGamePadState.Buttons.X == ButtonState.Pressed) { var laser = _laserManager.FireLocalLaserClient(gameTime, _localPlayer.Position, _localPlayer.Rotation, _playerColours[_localPlayer.NetworkID]); if (laser != null) { input.FirePressed = true; var dataPacket = _localPlayer.BuildUpdatePacket(); PlayerFiredPacket packet = NetworkPacketFactory.Instance.MakePlayerFiredPacket(dataPacket.XPosition, dataPacket.YPosition, dataPacket.Speed, dataPacket.Rotation); packet.TotalGameTime = (float)gameTime.TotalGameTime.TotalSeconds; // TOTAL GAME TIME NOT ELAPSED TIME! packet.LaserID = laser.LaserID; // Send the packet to the server SendMessageToTheServer(packet, MessageType.GI_ClientSend_PlayerFired); } } if (Application.APPLY_CLIENT_SIDE_PREDICTION) { _localPlayer.ApplyInputToPlayer(input, (float)gameTime.ElapsedGameTime.TotalSeconds); _localPlayer.Update((float)gameTime.ElapsedGameTime.TotalSeconds); } _localPlayer.UpdateAnimation(gameTime); return(input); }
private void UpdateButtons(InputInformation inputInfo) { if (inputInfo.CurrentMouseState.LeftButton == ButtonState.Pressed && inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) // Clicked { if (_connectBtnRect.Contains(inputInfo.CurrentMouseState.Position)) { if (!string.IsNullOrEmpty(_textbox.Text.String)) { // START GAME AS CLIENT OnClientStartRequested(_textbox.Text.String); } } else if (_serverBtnRect.Contains(inputInfo.CurrentMouseState.Position)) { // START GAME AS SERVER OnServerStartRequested("str"); } } else { if (_connectBtnRect.Contains(inputInfo.CurrentMouseState.Position)) { if (string.IsNullOrEmpty(_textbox.Text.String)) { _connectBtnColour = Color.Red; } else { _connectBtnColour = Color.LightGreen; } } else { _connectBtnColour = Color.Blue; } if (_serverBtnRect.Contains(inputInfo.CurrentMouseState.Position)) { _serverBtnColour = Color.LightGreen; } else { _serverBtnColour = Color.Blue; } } }
private void CheckBottomButtonClicked(InputInformation inputInfo) { switch (_state) { case WaitingRoomState.NotInRoomAbleToCreate: { // Is it possible to create a new room? Must be less rooms than max and this client can't currently be in a room if (_roomUIItems.Count < Server.MAX_ROOMS && string.IsNullOrEmpty(_joinedRoomID)) { // If mouse has been clicked if (inputInfo.CurrentMouseState.LeftButton == ButtonState.Pressed && inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { if (_buttonRect.Contains(inputInfo.CurrentMouseState.Position)) { // New room valid click SendMessageToTheServer(new BasePacket(), MessageType.WR_ClientRequest_CreateRoom); } } else if (inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) // Else if mouse is hovering { if (_buttonRect.Contains(inputInfo.CurrentMouseState.Position)) { _buttonColour = Color.LightGreen; } else { _buttonColour = Color.Blue; } } } else { _buttonColour = Color.Red; } break; } case WaitingRoomState.NotInRoomUnableToCreate: { _buttonColour = Color.Red; break; } case WaitingRoomState.InRoomWaitingForPlayers: { _buttonColour = Color.Red; break; } case WaitingRoomState.InRoomNotReady: { if (inputInfo.CurrentMouseState.LeftButton == ButtonState.Pressed && inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { if (_buttonRect.Contains(inputInfo.CurrentMouseState.Position)) { // ON READY UP SendMessageToTheServer(new BasePacket(), MessageType.GR_ClientRequest_Ready); _waitingForResponseFromServer = true; } } else if (inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) // Else if mouse is hovering { if (_buttonRect.Contains(inputInfo.CurrentMouseState.Position)) { _buttonColour = Color.LightGreen; } else { _buttonColour = Color.Orange; } } else { _buttonColour = Color.Orange; } break; } case WaitingRoomState.InRoomReady: { if (inputInfo.CurrentMouseState.LeftButton == ButtonState.Pressed && inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { if (_buttonRect.Contains(inputInfo.CurrentMouseState.Position)) { // ON UNREADY SendMessageToTheServer(new BasePacket(), MessageType.GR_ClientRequest_Unready); _waitingForResponseFromServer = true; } } else if (inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) // Else if mouse is hovering { if (_buttonRect.Contains(inputInfo.CurrentMouseState.Position)) { _buttonColour = Color.Orange; } else { _buttonColour = Color.LightGreen; } } else { _buttonColour = Color.LightGreen; } break; } } }
private void CheckRoomClicked(InputInformation inputInfo) { switch (_state) { case WaitingRoomState.NotInRoomUnableToCreate: case WaitingRoomState.NotInRoomAbleToCreate: { if (inputInfo.CurrentMouseState.LeftButton == ButtonState.Pressed && inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { for (int i = 0; i < _roomUIItems.Count; i++) { if (_roomUIItems[i].Rect.Contains(inputInfo.CurrentMouseState.Position) && (GameRoomState)_waitingRoom.Rooms[i].RoomState != GameRoomState.InSession && (GameRoomState)_waitingRoom.Rooms[i].RoomState != GameRoomState.Leaderboards) { SendMessageToTheServer(NetworkPacketFactory.Instance.MakeStringPacket(_waitingRoom.Rooms[i].RoomID), MessageType.WR_ClientRequest_JoinRoom); _waitingForResponseFromServer = true; } } } else if (inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { for (int i = 0; i < _roomUIItems.Count; i++) { if ((GameRoomState)_waitingRoom.Rooms[i].RoomState == GameRoomState.InSession || (GameRoomState)_waitingRoom.Rooms[i].RoomState == GameRoomState.Leaderboards) { _roomUIItems[i].BorderColour = Color.Red; } else if (_roomUIItems[i].Rect.Contains(inputInfo.CurrentMouseState.Position)) { _roomUIItems[i].BorderColour = Color.LightGreen; } else { _roomUIItems[i].BorderColour = Color.Blue; } } } break; } case WaitingRoomState.InRoomWaitingForPlayers: case WaitingRoomState.InRoomNotReady: { if (inputInfo.CurrentMouseState.LeftButton == ButtonState.Pressed && inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { for (int i = 0; i < _roomUIItems.Count; i++) { if (_waitingRoom.Rooms[i].RoomID == _joinedRoomID) { if (_roomUIItems[i].Rect.Contains(inputInfo.CurrentMouseState.Position)) { SendMessageToTheServer(NetworkPacketFactory.Instance.MakeStringPacket(_waitingRoom.Rooms[i].RoomID), MessageType.WR_ClientRequest_LeaveRoom); _waitingForResponseFromServer = true; } } } } else if (inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { for (int i = 0; i < _roomUIItems.Count; i++) { if (_waitingRoom.Rooms[i].RoomID == _joinedRoomID) { if (_roomUIItems[i].Rect.Contains(inputInfo.CurrentMouseState.Position)) { _roomUIItems[i].BorderColour = Color.Orange; } else { _roomUIItems[i].BorderColour = Color.LightGreen; } } else { if (_roomUIItems[i].Rect.Contains(inputInfo.CurrentMouseState.Position)) { _roomUIItems[i].BorderColour = Color.Red; } else { _roomUIItems[i].BorderColour = Color.Blue; } } } } break; } case WaitingRoomState.InRoomReady: { for (int i = 0; i < _roomUIItems.Count; i++) { if (_waitingRoom.Rooms[i].RoomID == _joinedRoomID) { _roomUIItems[i].BorderColour = Color.LightGreen; } else { _roomUIItems[i].BorderColour = Color.Blue; } } break; } } }
public void ProcessInput(GameTime gameTime, InputInformation inputInfo) { if (_sceneState == LeaderboardSceneState.WaitingForSelection) { if (inputInfo.CurrentMouseState.LeftButton == ButtonState.Pressed && inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { if (_rematchButtonRect.Contains(inputInfo.CurrentMouseState.Position)) { // READY _sceneState = LeaderboardSceneState.RematchSelected; SendMessageToTheServer(new BasePacket(), MessageType.LB_ClientSend_RematchReady); } else if (_exitButtonRect.Contains(inputInfo.CurrentMouseState.Position)) { // LEAVE GAME LeaveGame(); } } else if (inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) // If hover { if (_rematchButtonRect.Contains(inputInfo.CurrentMouseState.Position)) { _rematchButtonColour = Color.LightGreen; } else { _rematchButtonColour = Color.Blue; } if (_exitButtonRect.Contains(inputInfo.CurrentMouseState.Position)) { _exitButtonColour = Color.LightGreen; } else { _exitButtonColour = Color.Blue; } } } else if (_sceneState == LeaderboardSceneState.WaitingForExit) { _rematchButtonColour = Color.Red; // If clicked if (inputInfo.CurrentMouseState.LeftButton == ButtonState.Pressed && inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { if (_exitButtonRect.Contains(inputInfo.CurrentMouseState.Position)) { // LEAVE GAME LeaveGame(); } } else if (inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) // If hover { if (_exitButtonRect.Contains(inputInfo.CurrentMouseState.Position)) { _exitButtonColour = Color.Orange; } else { _exitButtonColour = Color.Blue; } } } else { _exitButtonColour = Color.Red; // If clicked if (inputInfo.CurrentMouseState.LeftButton == ButtonState.Pressed && inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) { if (_rematchButtonRect.Contains(inputInfo.CurrentMouseState.Position)) { // UNREADY _sceneState = LeaderboardSceneState.WaitingForSelection; SendMessageToTheServer(new BasePacket(), MessageType.LB_ClientSend_RematchUnready); } } else if (inputInfo.PreviousMouseState.LeftButton == ButtonState.Released) // If hover { if (_rematchButtonRect.Contains(inputInfo.CurrentMouseState.Position)) { _rematchButtonColour = Color.Orange; } else { _rematchButtonColour = Color.LightGreen; } } } }
public void ProcessInput(GameTime gameTime, InputInformation inputInfo) { UpdateTextbox(gameTime); UpdateButtons(inputInfo); }
public void ProcessInput(GameTime gameTime, InputInformation inputInfo) { }