Ejemplo n.º 1
0
        public void Unpack(NetIncomingMessage msg)
        {
            sequence = msg.ReadByte();

            inputs = new Inputs(
                msg.ReadByte(),
                msg.ReadByte(),
                msg.ReadByte(),
                msg.ReadByte(),
                msg.ReadByte()
                );
        }
Ejemplo n.º 2
0
        public void PredictPlayerFromInput(Inputs input)
        {
            CheckForPlayerEntity(Username);

            // Input Prediction
            // http://www.gabrielgambetta.com/?p=22

            Vector2 delta = Vector2.Zero;
            delta += (input.Up) ? new Vector2(0, -5) : Vector2.Zero;
            delta += (input.Down) ? new Vector2(0, 5) : Vector2.Zero;
            delta += (input.Left) ? new Vector2(-5, 0) : Vector2.Zero;
            delta += (input.Right) ? new Vector2(5, 0) : Vector2.Zero;

            // store previous position for lerp
            Vector2 currentPosition = (PlayerEntities[Username].GetComponent("Position") as Position).Vector2Pos;
            PlayerEntities[Username].DoAction("ChangeAbsPreviousPosition", new ChangePositionArgs(currentPosition));

            // store snapshot of move
            if (delta != Vector2.Zero)
                inputPredictionManager.addNewInput(currentPosition, delta);

            // make the move
            PlayerEntities[Username].DoAction("ChangeDeltaPosition", new ChangePositionArgs(delta));
            PlayerEntities[Username].DoAction("ChangeCurrentSmoothing", new ChangeCurrentSmoothingArgs(1));
        }
Ejemplo n.º 3
0
 public void HandleOutgoingMessages(Inputs inputs)
 {
     if (inputs.HasKeyDown())
     {
         InputsPacket inputPacket = new InputsPacket();
         inputPacket.inputs = inputs;
         inputPacket.sequence = ClientGameManager.Instance.Key;
         SendUnreliableData(inputPacket);
     }
 }