   
 }
 
+enum Contact : UInt32 {
+  case Pinned
+  case Moving
+}
+
 class Physical : Component {
   var isEnabled:Bool = true
   weak var node:SKNode?

  
}

class Reseting : Component {
  var isEnabled:Bool = true
  weak var node:SKNode?
  func didAddToNode() {
    
  }
}

class Movement : Component {
  var isEnabled:Bool = true
  weak var node:SKNode?
  func didAddToNode() {
    println("didAddToNode Movement \(self.node?.name)")
    self.node?.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: 40, height: 40))
    //    player.physicsBody?.collisionBitMask = 1
    enum Contact : UInt32 {
      case Enemy
      case Player
    }
    if(self.node?.name == "ENEMY") {
      let p = self.node?.physicsBody
      self.node?.physicsBody = nil
      self.node?.position = CGPoint(x: 100, y: 100)
      self.node?.physicsBody = p
      self.node?.physicsBody?.categoryBitMask = Contact.Enemy.toRaw()
      self.node?.physicsBody?.contactTestBitMask = Contact.Player.toRaw()
      self.node?.physicsBody?.collisionBitMask = 0//Contact.Player.toRaw()

      
    }
    else {
      self.node?.physicsBody?.categoryBitMask = Contact.Player.toRaw()
      self.node?.physicsBody?.contactTestBitMask = Contact.Enemy.toRaw()
      self.node?.physicsBody?.collisionBitMask = 0//Contact.Enemy.toRaw()
    }
    self.node?.physicsBody?.dynamic = true

  }
  func didRemoveFromNode() {
    println("didRemoveFromNode Movement \(self.node?.name)")
  }
  
  func didAddNodeToScene() {
    println("didAddNodeToScene Movement \(self.node?.name) and scene \(self.node?.scene?.name)")
    if(self.node?.name == "ENEMY") {
      self.node?.physicsBody?.applyImpulse(CGVector(5.0,5.0))
    }

  }
  
  func didRemoveNodeFromScene() {
    println("didRemoveNodeFromScene Movement \(self.node?.name)")
  }
  func didUpdate(time:NSTimeInterval) {
//    println("didUpdate \(time) Movement \(self.node?.name)")
    if(self.node?.name == "ENEMY") {
//     self.node?.physicsBody?.applyImpulse(CGVector(5.0,5.0))
   //   println(self.node?.physicsBody?)
    }
  }
  func didChangeSceneSizedFrom(previousSize:CGSize) {
    println("didChangeSceneSizedFrom \(previousSize) Movement \(self.node?.name)")
  }
  func didEvaluateActions() {
//    println("didEvaluateActions Movement \(self.node?.name)")
  }
  func didSimulatePhysics() {
//    println("didSimulatePhysics Movement \(self.node?.name)")
  }
  func didBeginContact(contact:SKPhysicsContact) {
//    println("didBeginContact \(contact) Movement \(self.node?.name)")
  }
  func didEndContact(contact:SKPhysicsContact) {
//    println("didEndContact \(contact) Movement \(self.node?.name)")
    if self.node?.name == "ENEMY" {
      let node = self.node!
      self.node?.removeComponentWithClass(Movement.self)
      node.addComponent(Movement())
    }
  }
  
  func didFinishUpdate() {
    println("didFinishUpdate MOVEMENT \(self.node?.name)")
    
  }

  
}



    player.addChild(gun)

    
    enemy.addComponent(Reseting())
    player.addComponent(Pinned())
//    gun.addComponent(Life())
    
    scene.addComponent(GravityLessBounds())
