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:

  1. User touches the rock

  2. Rock changes into a new costume “broken rocks”

  3. A “crunch sound is played then stopped”

  4. Score goes up by 1

  5. Rock is hidden then dissappeares

  6. Changes costume to “rock”, not broken

  7. Goes to random position

  8. Rock is then shown again

  9. If score is less than 20, game carries on, if not game ends by hiding rock.



Now that we have a main game loop, lets make sure the scores reset whenever the game is ran. This is extremely simple and only needs two blocks:

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

Popular posts from this blog

Junkbots - Conclusion

Junkbots - Spawning some rocks

Junkbots - Introduction