Moving Those Pucks
Handling the sprites here is a little different than in the Aquarium application, because when a puck slides into a goal, the user's score or the computer's score should be incremented and the puck should be taken out of action—which doesn't happen to fish. To make this happen, the code passes the position of both blockers to the method that moves each puck around, slide, and that method will return a value of 0 if the puck is still in play, -1 if it went into the computer's goal, and 1 if it went into the user's goal. Each Puck object also has a method named gone, which will return true if the puck is out of play (and therefore should not be moved or drawn).
The run method uses each puck's slide method to move the pucks and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access