Add Player Lives

mechanics space polish and systems

Adding a starting amount of lives

We can add in the starting number of lives. To do this drag in from Info a set lives to 3 block to the beginning of the on start loop.

mechanics space polish and systems

Change the overlap loop for our Enemy

In this game previously you may have had code where the player overlapping with a Static Enemy would be Game Over with the player losing.

lose a point

Another possibility is that you may have moving enemies with a different code structure. You can change to replace the Game Over lose block with a change lives by -1 block.

lose a point

Reflecting on what’s happening

Variables: In this example you are using a Variable of called life to keep track of the player lives. In this example you start with three and you update the value of that Variable everytime you bump into an enemy.

Change Listener: The on sprite kind overlap block is always listening out for a change where if there is a new overlap with an enemy the programme will run the code inside that block. This kind of Change Listener is often used in computer programmes to react to new situations.

Systems Dynamics: The use of new lives means that the balance of the game will be altered. This may make it easier so you may need to balance this out by making something in your game harder. This process of balancing out systems elements allow us to explore Systems Dynamics.

Test your Changes and Next Steps

Test your game to check that your changes have the desired behaviour and that there are no side effects. For example check that each time you touch an enemy your number of lives goes down by one.

There is a known side effect with some kinds of enemies where you lose more than one life. To avoid this you may need to make Player Immune pattern

This Game Pattern is one of many allowing you to make improvements to your platform game and to learn coding and wider computing concepts. Find more on the Game Pattern page.