 
 import SpriteKit
 
-class GameScene: SKScene {
+class GameScene: SKScene, SKPhysicsContactDelegate {
 
     var bird = SKSpriteNode()
     var bkgr = SKSpriteNode()
+    var ground = SKNode()
 
     override func didMoveToView(view: SKView) {
+        self.physicsWorld.contactDelegate = self
+        self.physicsWorld.gravity = CGVectorMake(0, -6.0)
 
         makeBackground()
+        makeGround()
         makeFlappingBird()
-        
+
     }
     
     override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

            bkgr.size.height = self.frame.height

            bkgr.runAction(slideBG)
            bkgr.zPosition = 0

            self.addChild(bkgr)
        }
    }

    func makeFlappingBird() {


        bird = SKSpriteNode(texture: birdTextureUp)

        bird.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMaxY(self.frame))
        bird.zPosition = 5      // Always on top
        bird.runAction(flap)

        bird.physicsBody = SKPhysicsBody(circleOfRadius: bird.size.height / 2)
        bird.physicsBody?.dynamic = true

        self.addChild(bird)


    }
}
