Beispiel #1
0
        private void HandleUpdatePlayerStateMessage(NetIncomingMessage im)
        {
            var message = new UpdatePlayerStateMessage(im);

            if (localPlayerId != message.Id)
            {
                if (networkManager.GetType().Equals(typeof(ServerNetworkManager)))
                {
                    networkManager.SendMessage(message);
                }

                Player player;
                if (this.playerManager.GetPlayer(message.Id) != null)
                {
                    player = this.playerManager.GetPlayer(message.Id);
                }
                else
                {
                    player = new Player(message.Id, 100, 100, 100, 100, 100, 30, 100, message.Position, 5f / 60f, 30, 1f, 1f, 1f, false);
                    player.Load(this.Content, "Models\\Characters\\vincent", space, graphics.GraphicsDevice, camManager.ActiveCamera.ViewMatrix, camManager.ActiveCamera.ProjectionMatrix);
                    playerManager.AddPlayer(player);
                }

                player.CharecterState = message.CharState;
                player.CharacterController.Body.LinearVelocity = message.Velocity;
                player.CharacterController.Body.Position       = message.Position;
                player.Position = message.Position;
                player.Rotation = message.Rotation;
                player.addWeapon(weaponManager.GetWeapon(message.CurrentWeaponID));
                player.Health = message.Health;
            }
        }
Beispiel #2
0
        public void HandleUpdatePlayerStateMessage(IGameMessage msg)
        {
            UpdatePlayerStateMessage message = (UpdatePlayerStateMessage)msg;

            var timeDelay = (float)(NetTime.Now - connection.GetLocalTime(message.MessageTime));

            player.EnableSmoothing = true;

            if (player.LastUpdateTime < message.MessageTime)
            {
                player.SimulationState.Position = message.Position += message.Velocity * timeDelay;
                player.SimulationState.Velocity = message.Velocity;
                player.SimulationState.Rotation = message.Rotation;

                player.LastUpdateTime = message.MessageTime;
            }
        }