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.
Detecting the player getting squashed is really simple. All we want to know is: does the last branch in the branchPositions
array equal playerSide
? If it does, the player is dead.
Add the following highlighted code that detects and executes when the player is squashed by a branch. We will talk about it later:
// Handle a flying log if (logActive) { spriteLog.setPosition( spriteLog.getPosition().x + (logSpeedX * dt.asSeconds()), &...