 
 class GameScene: SKScene, SKPhysicsContactDelegate {
     
-    let imagesAtlas = SKTextureAtlas(named: "FlappyAssets")
-    let flappyBird = SKSpriteNode(imageNamed: "Yellow_Bird_Wing_Straight")
-   
-    override func didMoveToView(view: SKView) {
+    var flappyBird:      SKSpriteNode!
+    var forwardMovement: SKNode!
+    var pipeMovement:    SKNode!
 
+    // MARK: #===== Init =====#
+
+    override func didMoveToView( view: SKView ) {
+
+        self.backgroundColor = SKColor( red: 81.0/255.0, green: 192.0/255.0, blue: 201.0/255.0, alpha: 1.0 )
+
+        forwardMovement = SKNode()
+        addChild(forwardMovement)
+        
         addSkyline()
         addForeground()
         addFlappyBird()

import SpriteKit

let spaceBetweenPipes = 100.0

struct flappyContactMasks {
    static let None      : UInt32 = 0

        physicsWorld.gravity = CGVectorMake(0,-5)
        physicsWorld.contactDelegate = self
        
        // TODO: create some pipes with some duratuon
        // TODO: track score of pipes passed
        
    }
    
    // MARK: #===== Frame Update =====#
    
    override func update( currentTime: CFTimeInterval ) {
        
        flappyBird.zRotation = self.constrain( -1, maximum: 0.5, attempt: flappyBird.physicsBody!.velocity.dy * ( flappyBird.physicsBody!.velocity.dy < 0 ? 0.005 : 0.002 ) )
        
    }


    // MARK: #===== Sprites =====#

   
    func addSkyline () {

        // TODO: there are two bugs, 1) there is a pixel between sprites. 2) there is a jump between the 3rd and 1st sprite
        
        let skylineTexture           = imagesAtlas.textureNamed( "Day_Background" )
        skylineTexture.filteringMode = SKTextureFilteringMode.Nearest
        
        let skylineMove    = SKAction.moveByX( -self.frame.width * 2.0, y: 0, duration: 15 )
        let skylineReset   = SKAction.moveByX( self.frame.width * 2.0, y: 0 , duration: 0 )
        let skylineActions = SKAction.repeatActionForever( SKAction.sequence( [skylineMove, skylineReset] ) )
        
        for i in 0...3 {
            let skyline = SKSpriteNode( texture: skylineTexture )
            skyline.position = CGPointMake( CGFloat(i) * skylineTexture.size().width, self.frame.height * 0.5 )
            skyline.runAction( skylineActions );
            forwardMovement.addChild( skyline )
        }
    }
    
