Junkbots - Scoring
Activity 7 - Scoring and breaking the rocks
This will be the main aim of the game. The code below will allow the user to touch the rock, it then breaks then disappears and a new rock spawns.
The first task is to start a scoring system. This will show the user their score and will update the score every time they hit the rock. It will also end the game when the user reaches a score of 20, you can make this score limit any score you want.
To keep score we’ll be creating our own variable. (a data holder). On the scratch blocks scroll down on the left onto the Variables block. Create a variable named score and tick the box, like below:
Our whole code for this part of the game will be in one big loop. The loop will repeat as long as our Score variable is less than our score limit, in this example it’s 20. To make this loop use the Control, Operators and Variable blocks together.
The next loop will run when the user touches the rock. When this is ran, the rock will break, the score will change and a new rock will spawn. Lets break it down step by step:
User touches the rock
Rock changes into a new costume “broken rocks”
A “crunch sound is played then stopped”
Score goes up by 1
Rock is hidden then dissappeares
Changes costume to “rock”, not broken
Goes to random position
Rock is then shown again
If score is less than 20, game carries on, if not game ends by hiding rock.
Your task:
Create a variable which holds the players score
Create a loop which runs while the players score is less than 20
Create another loop which checks if the player touches the rock, in this loop you should
Hide the rock when it’s touched
Change the score
Spawn a new rock in a new place
End the game when your score limit is reached
Reset the score every time a new game start
Comments
Post a Comment