<commit_before>//
//  GameScene.swift
//  SwiftInvaders
//
//  Created by <NAME> on 24/11/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import SpriteKit

enum CollisionType: UInt32 {
    case Edge   = 1
    case Player = 2
    case Bullet = 4
    case Enemy  = 8
}

class GameScene: SKScene, SKPhysicsContactDelegate {
    
    var player: SKSpriteNode?
    
    var isMovingLeft: Bool = false
    var isMovingRight: Bool = false
    var isShooting: Bool = false

    var shot: SKSpriteNode = SKSpriteNode(imageNamed: "laserRed01")
    
    var lastShotFired: CFTimeInterval = 0
    
    override func didMoveToView(view: SKView) {
        /* Initialize physics for scene */
        self.physicsWorld.contactDelegate = self
        self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
        self.physicsBody?.categoryBitMask = CollisionType.Edge.rawValue
        
        /* Intialize physics for a single shot */
        shot.physicsBody = SKPhysicsBody(rectangleOfSize: shot.size)
        shot.physicsBody?.categoryBitMask = CollisionType.Bullet.rawValue
        shot.physicsBody?.collisionBitMask = 0 // Make sure the bullet isn't affected by the collision
        shot.physicsBody?.affectedByGravity = false
        shot.physicsBody?.contactTestBitMask = CollisionType.Edge.rawValue
        
        /* Add player + enemies to scene. Both have their physics settings defined in the SKS file */
        if let childNode = self.childNodeWithName("player") as? SKSpriteNode {
            self.player = childNode
        }
        
        if let children = GameScene.unarchiveFromFile("Level1")?.children {
            let enemyGroup: SKNode = SKNode()
            for child: AnyObject in children {
                child.physicsBody??.categoryBitMask = CollisionType.Enemy.rawValue
                child.physicsBody??.collisionBitMask = 0
                child.physicsBody??.contactTestBitMask = CollisionType.Bullet.rawValue
                enemyGroup.addChild(child.copy() as SKNode)
            }
            self.addChild(enemyGroup)
        }
    }
    
    func didBeginContact(contact: SKPhysicsContact) {
        
    }
    
    override func update(currentTime: CFTimeInterval) {
        self.handleMovement()
        self.handleShooting(currentTime)
    }
    
    override func keyDown(theEvent: NSEvent) {
        self.handleInput(theEvent.keyCode, active: true)
    }
    
    override func keyUp(theEvent: NSEvent) {
        self.handleInput(theEvent.keyCode, active: false)
    }
    <commit_msg>Remove nodes based on collision detection<commit_after>//
//  GameScene.swift
//  SwiftInvaders
//
//  Created by <NAME> on 24/11/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import SpriteKit

enum CollisionType: UInt32 {
    case Edge   = 1
    case Player = 2
    case Bullet = 4
    case Enemy  = 8
}

class GameScene: SKScene, SKPhysicsContactDelegate {
    
    var player: SKSpriteNode?
    
    var isMovingLeft: Bool = false
    var isMovingRight: Bool = false
    var isShooting: Bool = false

    var shot: SKSpriteNode = SKSpriteNode(imageNamed: "laserRed01")
    
    var lastShotFired: CFTimeInterval = 0
    
    override func didMoveToView(view: SKView) {
        /* Initialize physics for scene */
        self.physicsWorld.contactDelegate = self
        self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
        self.physicsBody?.categoryBitMask = CollisionType.Edge.rawValue
        
        /* Intialize physics for a single shot */
        shot.physicsBody = SKPhysicsBody(rectangleOfSize: shot.size)
        shot.physicsBody?.categoryBitMask = CollisionType.Bullet.rawValue
        shot.physicsBody?.collisionBitMask = 0 // Make sure the bullet isn't affected by the collision
        shot.physicsBody?.affectedByGravity = false
        shot.physicsBody?.contactTestBitMask = CollisionType.Edge.rawValue
        
        /* Add player + enemies to scene. Both have their physics settings defined in the SKS file */
        if let childNode = self.childNodeWithName("player") as? SKSpriteNode {
            self.player = childNode
        }
        
        if let children = GameScene.unarchiveFromFile("Level1")?.children {
            let enemyGroup: SKNode = SKNode()
            for child: AnyObject in children {
                child.physicsBody??.categoryBitMask = CollisionType.Enemy.rawValue
                child.physicsBody??.collisionBitMask = 0
                child.physicsBody??.contactTestBitMask = CollisionType.Bullet.rawValue
                enemyGroup.addChild(child.copy() as SKNode)
            }
            self.addChild(enemyGroup)
        }
    }
    
    func didBeginContact(contact: SKPhysicsContact) {
        var first: SKPhysicsBody = contact.bodyA
        var second: SKPhysicsBody = contact.bodyB

        if first.categoryBitMask > second.categoryBitMask {
            second = contact.bodyA
            first = contact.bodyB
        }
        
        if first.categoryBitMask == CollisionType.Bullet.rawValue {
            if second.categoryBitMask == CollisionType.Enemy.rawValue {
                first.node?.removeFromParent()
                second.node?.removeFromParent()
            } else if second.categoryBitMask == CollisionType.Enemy.rawValue {
                first.node?.removeFromParent()
            }
        }
    }
    
    override func update(currentTime: CFTimeInterval) {
        self.handleMovement()
        self.handleShooting(currentTime)
    }
    
    override func keyDown(theEvent: NSEvent) {
        self.handleInput(theEvent.keyCode, active: true)
    }
    
    override func keyUp(theEvent: NSEvent) {
        self.handleInput(theEvent.keyCode, active: false)
    }
    
{'fraction_non_alphanumeric': 0.08324607329842931, 'fraction_numerical': 0.007678883071553229, 'mean_word_length': 2.324245939675174, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3924322', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1632, 'n_words': 373}