Handling death
Every game must end badly, with either the player running out of time (which we have already handled) or getting squashed by a branch. The mayfly is an aquatic creature that lives anywhere between a few hours and a few days. Playing the Timber!!! game is like being a mayfly in a hurry – you’re either running out of time or feeling the branch of destiny squashing your hopes! Our hero in the Timber!!! game may only last a few seconds, and even an experienced player will struggle to last more than a few minutes.
Fortunately, detecting the player getting squashed is really simple. All we want to know is whether the last branch in the branchPositions
array equals playerSide
. If it does, the player is dead.
Add the highlighted code that detects this, and then we will discuss everything we need to do when the player is squashed:
// Handle a flying log
if (logActive)
{
spriteLog.setPosition(
spriteLog...