How to make a racket and ball game in Scratch ?

Scratch 16-05-25
34 0

Tutorial plan

1- Objective of the tutorial

2- Step-by-Step to create a racket and ball game

 

 

Objective of the tutorial

The goal of this project is to create a classic arcade-style game where the player uses a paddle (racket) to bounce a ball and prevent it from falling off the bottom of the screen.

Use the arrow keys (or mouse) to move the paddle left and right and keep the ball bouncing. The game ends if the ball touches the bottom of the screen.

What You Will Learn ?

How to create and control sprites (ball and paddle)

How to use motion and control blocks

How to detect collisions between sprites

How to use variables to track score or lives

How to make the game more interactive with sound effects and game over logic

 

Step-by-Step to create a racket and ball game

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.

3) 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 2: 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.

3) Orient the ball sprite:

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.

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

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

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

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 3: 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 4: 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 5: 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 comment

Leave a comment

Veuillez noter s'il vous plaît*

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

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info