Give it a try!
Let´s get started:
1. Select or draw your backdrop.
2. Create two sprites: a paddle for the user to control and a ball the user will be playing with.
3. Make your paddle sprite interactive:
- Set x to the mouse x position
- Set y to a fixed position (-160)
4. The next step is to move the ball.
Set the ball starting position:- Set y to the upper value of the screen.
- Set x to a random position along the x axis between to numbers: the more on the left (-240) and the more on the right (240) of the screen.
Now lets make the ball fall down:
- In a forever block decrease the y value by 5.
If the ball touches the paddle, the ball will go to its stating position and it will start to fall down again.
But if the ball touches the lowest part of the screen, the ball will disappear and start again.
We can do it by checking the ball y value:
- If y is smaller than -180 the ball will go to the starting point.
7. Now keep the score:
- Add a variable to score the times you catch the ball with the paddle.
- Initialize it to cero.
- If the ball touches the paddle, increase the score by 1.
- But if the ball touches the ground, decrease the score by 1.
8. Time the game!
This time we can use the timer variable in the Sensing Blocks.Click on the paddle Script tap:
- Reset the timer at the beginning of the program:
- When the timer gets bigger than 30 seconds the program will end and a message with our score will pop up on the screen.
9. What about having many balls falling down at the same time?
- Duplicate the ball sprite many times and try to catch them all!!!