Laying the foundations
So far, we have learned through small bits of code, individually added to the GameScene
class. The intricacy of our application is about to increase. To build a complex game world, we will need to construct reusable classes and actively organize our new code.
Adopting a protocol for consistency
To start, we want individual classes for each of our game objects (a bee class, a player penguin class, a power-up class, and so on). Furthermore, we want all of our game object classes to share a consistent set of properties and methods. We can enforce this commonality by creating a protocol, or a blueprint, for our game classes. The protocol does not provide any functionality on its own, but each class that adopts the protocol must follow its specifications exactly before Xcode can compile the project. Protocols are very similar to interfaces, if you are from a Java or C# background.
Add a new file to your project (right-click in the project navigator and choose New File, then...