+21622886281
Scratch

Racket and ball game with Scratch

Description of the racket and ball game with Scratch

Creating the paddle-and-ball game with Scratch software starts with everyone’s favorite sprite: a ball. Whether on a beach or a tennis court, in real life or in the virtual world, throwing, catching, throwing, blocking or rolling this object makes us happy.

So we decided to show you how to create a racket-ball game in Scratch.

The object of the game is to bounce the ball on the racket: when the ball bounces you win a point and the game continues, when the ball falls on the ground the game stops. The racket is directed to the left or to the right by the two arrows (right and left) of the keyboard.

Step 1: Create the racket sprite :

1) Go to the new sprites section and select the paint icon.

2) Draw the racket sprite using the drawing editor.

Step 2: Move the racket left and right

Insert these program blocks in the code area of ​​the racket sprite which allows the racket to be directed to the left or to the right using the two arrows (right and left) on the keyboard.

Step 3: Create the ball sprite

1) Go to the new sprites section and select the paint icon.

2) Draw the ball sprite using the drawing editor.

Step 4: Orient the ball sprite:

1) First of all, we are going to set up the point counter called « score », so that each bounce on the racket increases the score.

In the Variable Category, click the Create Variable Button and name the variable score.

2) We insert the block when the green flag is clicked from the Events category:

3) we add the set score to 0 block from the Variables category:

4) Place the ball in the initial position using this block from the Movement category.

5) We will now direct the movement of the ball in a random way using these blocks from the Motion category:

And get the first part of the program for the ball:

Step 5: MOVE THE BALL

For the ball to move in the scene in an autonomous way it is necessary to put the Block to advance of 5 steps in the block to repeat indefinitely.

Then we add the block bounce if the edge is reached so that the ball changes direction if it touches the edges of the stage.

Step 6 – BOUNCE ON THE RACKET

We will need to use a condition for this Script.

If the Ball sprite touches the Paddle sprite then:

– change direction

– add 1 to the score.

In the Control Category, drag the If _ Then Block.

In the Sensing Category, drag the Block touching Racket.

In the Variables Category, drag the Block add 1 to score.

Step 7 – Game End

The game ends when the sprite ball hits the ground floor.

So we are going to use the y ordinate of the ball to test if the ball hits the ground and the stop all block to stop all scripts in the game.

1- In the Control Category, drag the if _ then block.

2- Insert the block (y_ordinate) < (-150) in the if block condition.

3- Insert the two blocks say(‘End game’) and stop all inside the if then block.

Here is the final ball sprite program:




0 commentaire


Leave a comment

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Scroll to Top