Book Image

Game Development with Swift

By : Stephen Haney
Book Image

Game Development with Swift

By: Stephen Haney

Overview of this book

Table of Contents (18 chapters)
Game Development with Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The power-up star logic


When the player contacts the star, we will grant invulnerability for a short time and give the player great speed to power through encounters. Follow these steps to implement the power-up:

  1. In Player.swift, add a new function to the Player class, as shown here:

    func starPower() {
        // Remove any existing star power-up animation, if
        // the player is already under the power of star
        self.removeActionForKey("starPower")
        // Grant great forward speed:
        self.forwardVelocity = 400
        // Make the player invulnerable:
        self.invulnerable = true
        // Create a sequence to scale the player larger,
        // wait 8 seconds, then scale back down and turn off
        // invulnerability, returning the player to normal: 
        let starSequence = SKAction.sequence([
            SKAction.scaleTo(1.5, duration: 0.3),
            SKAction.waitForDuration(8),
            SKAction.scaleTo(1, duration: 1),
            SKAction.runBlock {
                self.forwardVelocity = 200
                self.invulnerable...