4. Scoring and Game Over
Step 1: Creating a Score Variable
Let's add a scoring system to our game.
1. Go to the "Variables" section and click "Make a Variable".
2. Name it "Score" and click OK.
3. In the Ball sprite's script, add a "set Score to 0" block at the beginning of your script (after the green flag block).
Step 2: Increasing the Score
We'll increase the score each time the ball hits the paddle.
1. In the Ball sprite's script, find your "if touching (Paddle)" block.
2. Inside this block, after the "point in direction" block, add a "change Score by 1" block.
Explanation: This increases the score by 1 every time the ball bounces off the paddle.
Step 3: Implementing Game Over
Let's end the game when the ball passes the paddle.
1. In the Ball sprite's script, add an "if then" block after your "if touching (Paddle)" block.
2. In the condition, use a "< [] >" block and fill it with "x position" and "-240".
3. Inside this if block, add a "broadcast (message1)" block and create a new message called "Game Over".
4. Add a "stop all" block after the broadcast block.
Step 4: Creating a Game Over Screen
Let's create a game over message.
1. Create a new sprite and use the text tool to write "Game Over".
2. In this new sprite's script tab, add a "when I receive (Game Over)" block.
3. Attach a "show" block to make the message appear.
4. At the start of your game (in a "when green flag clicked" script), add a "hide" block to ensure the message is hidden initially.