• import SpriteKit


    struct CollisionCategoryBitmask {

        static let Player: UInt32 = 0x00

        static let Star: UInt32 = 0x01

        static let Platform: UInt32 = 0x02

    }


    enum PlatformType: Int {

        case Normal = 0

        case Break

    }


    enum StarType: Int {

        case Normal = 0

        case Special

    }


    class GameObjectNode: SKNode {

        func collisionWithPlayer(player: SKNode) -> Bool {

            return false

        }

        

        func checkNodeRemoval(playerY: CGFloat) {

            if playerY > self.position.y + 300.0 {

                self.removeFromParent()

            }

        }

    }


    class PlatformNode: GameObjectNode {

        var platformType: PlatformType = .Normal

        

        override func collisionWithPlayer(player: SKNode) -> Bool {

            // 1

            // Only bounce the player if he's falling

            if player.physicsBody?.velocity.dy < 0 {

                // 2

                player.physicsBody?.velocity = CGVector(dx: player.physicsBody!.velocity.dx, dy: 250.0)

                

                // 3

                // Remove if it is a Break type platform

                if platformType == .Break {

                    self.removeFromParent()

                }

            }

            

            // 4

            // No stars for platforms

            return false

        }

    }


    class StarNode: GameObjectNode {

        var starType: StarType = .Normal

        let starSound = SKAction.playSoundFileNamed("Ping.wav", waitForCompletion: false)

        

        override func collisionWithPlayer(player: SKNode) -> Bool {

            // Boost the player up

            player.physicsBody?.velocity = CGVector(dx: player.physicsBody!.velocity.dx, dy: 400.0)

            

            // Play sound

            runAction(starSound, completion: {

                // Remove this Star

                self.removeFromParent()

            })

            

            // The HUD needs updating to show the new stars and score

            return true

        }

    }