Adding a new enemy - the Mad Fly
Pierre Penguin will need to dodge more than just Bees to accomplish his goal. We will add a few new enemies in this chapter, starting with the MadFly
class. The Mad Fly is quite grumpy, as you can see:
Adding the MadFly class
MadFly
is another straightforward class; it looks a lot like the bee
code. Create a new Swift file named MadFly.swift
and enter this code:
import SpriteKit class MadFly: SKSpriteNode, GameSprite { var initialSize = CGSize(width: 61, height: 29) var textureAtlas:SKTextureAtlas = SKTextureAtlas(named: "Enemies") var flyAnimation = SKAction() init() { super.init(texture: nil, color: .clear, size: initialSize) self.physicsBody = SKPhysicsBody(circleOfRadius: size.width / 2) self.physicsBody?.affectedByGravity = false createAnimations() self.run(flyAnimation) &...