arrow_back Bonus Points!
Sometimes games that have enemies to avoid, but also have prizes to catch. This screencast will show you how to make a sprite that gives you bonus points if caught.
First, you need to create the bonus sprite. This example will use an apple, but you can select whatever you would like.
Because this sprite will be a prize, it will start the game hidden.
Then, the apple should appear at random times.
To make something happen randomly, you can use an if statement, a “pick random” block, and an equals operator.
This will say: Well, when the sprite appears… It should glide to a spot...
Then it should hide. In order to keep making new random numbers for the entire game, place this code inside a forever loop.
This code now reads: That seems right! Try it!
This is a good time to tinker with the values to see how you can change game play.
Play around to see what happens when you change the values.
Looks good so far… Oh! The computer never told the apple to go back to where it started. After the apple moves to the right side of the screen and hides, it needs to go back to the left side of the screen.
To make that happen, add a “go-to” block just after the “hide” block, and put another one at the beginning of the program.
That way, the apple always starts in the same spot. Test your code to see if it works.
Looks good! Now that the apple is moving, the player should receive points for touching it. To do that, go back to the fish sprite.
You want the fish to score points if it is touching the apple. To do that, put the if block into your my program, then add a “touching” block and set the value to apple.
When the fish is touching the apple, you want the score to change by 5.
Add a "change score by block" that will change the score by 5 points.
When the fish touches the apple, 5 points get added.
Feel free to use your own numbers. This example started at 10, which is kind of small, but it was a good place to start testing.
The bonus sprite can be as rare or as common as you’d like in your game. You can also make the speed of the sprite slower or faster by changing the timing in the glide block.
Feel free to change the amount of points the bonus sprite gives you.
This is your chance to tinker with the code and make your game exactly the way you want it.