Coding at Home: May 20th, Build an Aquarium App, Part 3

Join us today for probably our last session on building an app in Swift Playgrounds! Live on Twitch at 1pm, Irish time!

There’s so much more we could do; we could spend weeks refining our work so far into a game or a full-fledged app.

Today’s Session

Today we’re going to focus on rudimentary hit testing… to see when one component we’ve added to the space is near another one.

We’ll use some functions defined for us inside the guts of the playground, including a method on the Point type called distance(from:). This will return us a Double, which we can use to figure out if two components appear to be touching or not.

This would be an important thing to calculate if we were to make a game where collisions with other objects might be a bad thing (or a good thing, depending on your game).

We’ll also harken back to chapter 10 of Everyone Can Code Puzzles and do some refactoring… we’ve been slapping code together without too much foresight thus far. Now we’ll revise our code a bit and make things that little bit neater.

A major goal of refactoring is often to make life easier for our future self: when we sit back down to go further with our app or game we’ll thank ourself for packaging code into a function or storing something in a variable so we could use it later.

See you at 1pm!

Leave a Reply

Your email address will not be published. Required fields are marked *