Пример #1
0
        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);
            }
        }
Пример #2
0
        public KeyboardMovementInput MakeKeyboardMovementInput()
        {
            KeyboardMovementInput input = new KeyboardMovementInput
            {
                LeftPressed  = false,
                RightPressed = false,
                UpPressed    = false,
                DownPressed  = false,
                FirePressed  = false
            };

            return(input);
        }
Пример #3
0
        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);
        }
Пример #4
0
        public void ApplyInputToPlayer(ref ObjectState state, KeyboardMovementInput input, float deltaTime)
        {
            if (input.DownPressed)
            {
                state.Speed -= Application.PLAYER_ACCELERATION_SPEED * deltaTime;
            }

            if (input.UpPressed)
            {
                state.Speed += Application.PLAYER_ACCELERATION_SPEED * deltaTime;
            }

            if (input.LeftPressed)
            {
                state.Rotation -= Application.PLAYER_ROTATION_SPEED * deltaTime;
            }

            if (input.RightPressed)
            {
                state.Rotation += Application.PLAYER_ROTATION_SPEED * deltaTime;
            }
        }
Пример #5
0
 public void ApplyInputToPlayer(KeyboardMovementInput input, float deltaTime)
 {
     ApplyInputToPlayer(ref PlayerState, input, deltaTime);
 }