Example #1
0
    /**
     * Mueve un jugador en alguna dirección.
     */
    public Packet Move(Packet request)
    {
        int       id         = request.Reset(6).GetInteger();
        BitBuffer bb         = request.GetBitBuffer();
        float     Δt         = bb.GetFloat(0, 1, 0.0001f);
        int       directions = bb.GetInt(0, 10);
        float     delta      = Δt * config.playerSpeed;

        LoadGhostFor(id);
        for (int k = 0; k < directions; ++k)
        {
            switch (bb.GetDirection())
            {
            case Direction.FORWARD: {
                ghostTransform.Translate(0, 0, delta);
                break;
            }

            case Direction.STRAFING_LEFT: {
                ghostTransform.Translate(-delta, 0, 0);
                break;
            }

            case Direction.BACKWARD: {
                ghostTransform.Translate(0, 0, -delta);
                break;
            }

            case Direction.STRAFING_RIGHT: {
                ghostTransform.Translate(delta, 0, 0);
                break;
            }

            case Direction.ROTATE_RIGHT: {
                ghostTransform.Rotate(0, 10 * delta, 0);
                break;
            }

            case Direction.ROTATE_LEFT: {
                ghostTransform.Rotate(0, -10 * delta, 0);
                break;
            }
            }
        }
        SaveGhostFor(id);
        return(GetResponseHeader(request.Reset(), 0).Build());
    }