     
     required override init(size: CGSize) {
         super.init(size: size)
+        
     }
     
     required init?(coder aDecoder: NSCoder) {
         super.init(coder: aDecoder)
         self.physicsWorld.contactDelegate = self
-        self.physicsWorld.gravity = CGVectorMake(0.0, -0.9)
         self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
+        
+        motionManager.startDeviceMotionUpdatesToQueue(NSOperationQueue(), withHandler: { [unowned self] (motion:CMDeviceMotion!, error:NSError!) -> Void in
+            let x = motion.gravity.x
+            let y = motion.gravity.y
+            let angle = atan2(y, x) + M_PI_2;
+            // 1.57 is new 0
+            let tilt = CGFloat(1.57 - angle)
+            if self.birdNode.mode == .Landing {
+                self.birdNode.physicsBody?.applyImpulse(CGVector(dx: -tilt, dy: 0.0))
+                let rotateAction = SKAction.rotateToAngle(tilt, duration: NSTimeInterval(0.1))
+                self.birdNode.runAction(rotateAction)
+                //SKAction.rotateByAngle(rotateAngleLeft, duration: Double(durationLeft))
+            }
+        })
     }
     
     override func didMoveToView(view: SKView) {

    let birdNode = FlyingBirdNode.bird()
    let cable1 = SKSpriteNode(imageNamed: "cable1")
    let cable2 = SKSpriteNode(imageNamed: "cable2")

    var audioPlayer:AVAudioPlayer?
    


import SpriteKit
import AVFoundation
import CoreMotion

private let spriteLineCategory:UInt32 = 0x1 << 1;

