Skip to content
mtso edited this page May 26, 2016 · 2 revisions

At the moment, the GameScene controls most of the logic in the game: the GameScene creates and restarts new game sessions, initializes the Penguin and IcebergGenerator, keeps track of the game state (gameOver true/false), controls the camera of the game, updates for detecting intersections between the penguin and icebergs, updates the score (increments one on each iceberg landing), and provides utilities such as a screenshake effect and overloading the minus sign operator to work on CGPoints.

The Penguin takes care of the targeting control in its own touchesBegan, *Moving, and *Ended overrides. The one thing that should intuitively be in the Penguin class but is instead in the GameScene object is the penguin's double jumping control. This is because the Penguin's touchesBegan won't be called if the touch is outside of the frame of the Penguin. So the GameScene calls the doubleJumping method when the penguin.inAir is true and when penguin.doubleJumped is false to shift the entire Penguin node in the opposite direction of a touch in the scene. penguin.doubleJumped is then set to false within the Penguin object after the jump method finishes.

So this means that the current penguin behavior is as follows:

while the penguin is not in the air, the GameScene checks to make sure that the penguin intersects with at least one iceberg.
penguin.inAir is false -> touching the penguin makes the targeting reticle show up, then releasing calls penguin.jump(). while the penguin is jumping, penguin.inAir is true. (It is then possible to touch the penguin again to make the targeting show up, but jumping again is not allowed while the penguin is in the air. Once the penguin lands, jumping on touch release is allowed again)
while the penguin is in the air, it is possible to make one 'double jump' that nudges the penguin in a direction opposite of the touch. this action does not increase the altitude or duration of the jump at all, and is canceled once the penguin lands so that the penguin 'sticks' to the iceberg

Double jump (second move action applied only once while the penguin is in the air) is implemented in the GameScene instead of the Penguin SKSpriteNode subclass because the initial TouchesBegan is outside of the Penguin node.

The Iceberg Generator takes care of figuring out when to create new icebergs and when to remove them. The IcebergGenerator's update method should be called during the GameScene's update while a game is in session.

The Iceberg class is used mostly by the Iceberg Generator. The one instance when the GameScene needs to call the sink(_:completion:) method in the Iceberg class is after detecting a collision between the penguin's shadow and an iceberg (meaning the penguin has landed on it).

Clone this wiki locally