Beispiel #1
0
    private void OnNetPlayerData(NetworkPlayer netPlayer, TankBattleCommand header)
    {
        switch (header.msg)
        {
        case TankBattleMessage.QUIT:
            RemovePlayer(netPlayer);
            break;

        default:
            break;
        }

        try
        {
            var pc = netPlayer.playerController as TankPlayerController;

            // process tank movement
            switch (header.tankMove)
            {
            case TankMovementOptions.FWRD:
                pc.MoveForward(1.0f);
                pc.MoveRight(0.0f);
                break;

            case TankMovementOptions.BACK:
                pc.MoveForward(-1.0f);
                pc.MoveRight(0.0f);
                break;

            case TankMovementOptions.LEFT:
                pc.MoveForward(0.0f);
                pc.MoveRight(-1.0f);
                break;

            case TankMovementOptions.RIGHT:
                pc.MoveForward(0.0f);
                pc.MoveRight(1.0f);
                break;

            case TankMovementOptions.HALT:
                pc.MoveForward(0.0f);
                pc.MoveRight(0.0f);
                break;

            default:
                Debug.LogError("Unknown movement.");
                break;
            }

            switch (header.cannonMove)
            {
            case CannonMovementOptions.LEFT:
                pc.RotateRight(-1.0f);
                break;

            case CannonMovementOptions.RIGHT:
                pc.RotateRight(1.0f);
                break;

            case CannonMovementOptions.HALT:
                pc.RotateRight(0.0f);
                break;

            default:
                Debug.LogError("Unknown cannon movement.");
                break;
            }

            // process tank actions
            if (header.fireWish == 1)
            {
                pc.Fire();
            }
        }
        catch (NullReferenceException ex)
        {
            Debug.LogError(ex.Message);
        }
    }
Beispiel #2
0
    private void OnNetPlayerData(NetworkPlayer netPlayer, TankBattleCommand header)
    {
        switch (header.msg)
        {
            case TankBattleMessage.QUIT:
                RemovePlayer(netPlayer);
                break;
            default:
                break;
        }

        try
        {
            var pc = netPlayer.playerController as TankPlayerController;

            // process tank movement
            switch (header.tankMove)
            {
                case TankMovementOptions.FWRD:
                    pc.MoveForward(1.0f);
                    pc.MoveRight(0.0f);
                    break;
                case TankMovementOptions.BACK:
                    pc.MoveForward(-1.0f);
                    pc.MoveRight(0.0f);
                    break;
                case TankMovementOptions.LEFT:
                    pc.MoveForward(0.0f);
                    pc.MoveRight(-1.0f);
                    break;
                case TankMovementOptions.RIGHT:
                    pc.MoveForward(0.0f);
                    pc.MoveRight(1.0f);
                    break;
                case TankMovementOptions.HALT:
                    pc.MoveForward(0.0f);
                    pc.MoveRight(0.0f);
                    break;
                default:
                    Debug.LogError("Unknown movement.");
                    break;
            }

            switch (header.cannonMove)
            {
                case CannonMovementOptions.LEFT:
                    pc.RotateRight(-1.0f);
                    break;
                case CannonMovementOptions.RIGHT:
                    pc.RotateRight(1.0f);
                    break;
                case CannonMovementOptions.HALT:
                    pc.RotateRight(0.0f);
                    break;
                default:
                    Debug.LogError("Unknown cannon movement.");
                    break;
            }

            // process tank actions
            if (header.fireWish == 1)
            {
                pc.Fire();
            }
        }
        catch (NullReferenceException ex)
        {
            Debug.LogError(ex.Message);
        }
    }