Goal:
Let’s code the rocks in the game.
We want to constantly check if the “Sharky” sprite touched the rocks.
If a rock touches the Shark, then we want to subtract one from the player’s life and then broadcast a new “HealthLost!” message.
Then we need to check that if the player’s Lives is less than 1, then the “GameOver!” message will be sent.
Steps:
- Click on the “Rocks” sprite create the shown code.
- From Events, place a when green flag clicked block.
- From Control, place a forever block and place an if block inside it.
- From Sensing, place a touching mouse-pointer block and change it to touching Sharky.
- From Variables, place a change by block and set it to Lives: and set the number to -1.
- From Events, place a broadcast block and change it to HealthLost!
- From Looks, place a hide block.
- From Control, place an if block.
- From Operators, place a < block.
- From Variables place a Lives: block on the left side of the < block and set the right side to 1.
- From Control place a braodcast block and set it to GameOver!