We’ll be back again today with our app project in Swift Playgrounds, live at 1pm, Irish time on Twitch!
Yesterday we added a rough hit detection function to tell when we were near another component, which might come in handy if we’re building an app or game where we want to be careful for other objects on the screen.
To do this we looked deep inside the guts of the Swift playground to find the HelperFunctions.swift file, where there was a handy
distance(from:) function defined on the
Point type. This function did a lot of the hard work of figuring out how far away two points on our grid were from each other.
From there we could figure out if it would look like the images for those components were touching or not.
We also even added a Game Over label for our game, when we did detect a collision.
Today we’ll be going back to the app just one more time, I promise!
We’ll add a counter for our game/app now. This will let us keep track of our score, whatever we determine that to be.
And the last thing we’ll do is add a label to show that score to the player.
See you at 1pm!