Приключение/Приключение Shared/Sprites/Archer.swift

/*
  Copyright (C) 2014 Apple Inc. All Rights Reserved.
  See LICENSE.txt for this sample’s licensing information
  
  Abstract:
  
        Defines the class for the archer hero character
      
*/
 
import SpriteKit
 
let kArcherProjectileSpeed = 8.0
 
var sSharedArcherProjectile = SKSpriteNode()
var sSharedArcherProjectileEmitter = SKEmitterNode()
 
var kLoadSharedArcherAssetsOnceToken: dispatch_once_t = 0
 
class Archer: HeroCharacter {
    // MARK: Initializers
 
    convenience init(atPosition: CGPoint, withPlayer: Player) {
        let atlas = SKTextureAtlas(named: "Archer_Idle")
        let texture = atlas.textureNamed("archer_idle_0001.png")
 
        self.init(atPosition: atPosition, withTexture: texture, player: withPlayer)
    }
 
    // MARK: Setup
 
    override func projectile() -> SKSpriteNode {
        return sSharedArcherProjectile
    }
 
    override func projectileEmitter() -> SKEmitterNode {
        return sSharedArcherProjectileEmitter
    }
 
    // MARK: Asset Pre-loading
 
    class func loadSharedAssets() {
        dispatch_once(&kLoadSharedArcherAssetsOnceToken) {
            sSharedArcherProjectile = SKSpriteNode(color: SKColor.whiteColor(), size: CGSize(width: 2.0, height: 24.0))
            sSharedArcherProjectile.name = "Projectile"
            
            // Assign the physics body; unwrap the physics body to configure it.
            sSharedArcherProjectile.physicsBody = SKPhysicsBody(circleOfRadius: kProjectileCollisionRadius)
            sSharedArcherProjectile.physicsBody!.categoryBitMask = ColliderType.Projectile.rawValue
            sSharedArcherProjectile.physicsBody!.collisionBitMask = ColliderType.Wall.rawValue
            sSharedArcherProjectile.physicsBody!.contactTestBitMask = sSharedArcherProjectile.physicsBody!.collisionBitMask
 
            sSharedArcherProjectileEmitter = SKEmitterNode.nodeWithName("ArcherProjectile")
 
            self.idleAnimationFrames = loadFramesFromAtlasWithName("Archer_Idle")
            self.walkAnimationFrames = loadFramesFromAtlasWithName("Archer_Walk")
            self.attackAnimationFrames = loadFramesFromAtlasWithName("Archer_Attack")
            self.getHitAnimationFrames = loadFramesFromAtlasWithName("Archer_GetHit")
            self.deathAnimationFrames = loadFramesFromAtlasWithName("Archer_Death")
 
            let actions = [
                SKAction.colorizeWithColor(SKColor.whiteColor(), colorBlendFactor: 10.0, duration: 0.0),
                SKAction.waitForDuration(0.75),
                SKAction.colorizeWithColorBlendFactor(0.0, duration: 0.25)
            ]
 
            self.damageAction = SKAction.sequence(actions)
        }
    }
}