You are on page 1of 2

SCRATCH lesson three

adding variables to pong


Setting up variables
YOU NEED A WORKING “PONG” GAME TO DO THIS
TASK.

If you do not have this, use the version on

Click on

Choose For all sprites

Call the variable Score and click OK

Add to variable blocks to the start of your program.

These blocks are added to code used to control your


ball

These blocks will initialise your variables – the score


is set to 0 and the bat speed is set to 4

Using the variables


We will change the code slightly so that the ball speed
is determined by the Speed variable.

We do this as follows:

We then change the code so that if the ball hits the bat
the score will increase by 10 and the ball speed will
increase by 1.

3
variables in pong: extension

Does your pong game work? Good! See if you can develop it further

Could you set a target score for


the player and use a variable to
store this?
w
Can you get your program to
check the players score and then
end the game if they reach the
target?

To extend your learning further: Why not add Lives to your game?

Creating a Lives variable should be quite easy but you


would need to think about things like:

- What would need to happen to the ball when a life


is lost?

- What would happen when the lives run out?

- Is there a way that a player could earn additional


lives?

You could create a “win game” target

When you have finished, explain your learning:

Right-click & choose add comment

Explain what you have done AND why next to your code

Explain how VARIABLES have been used

Press the Printscreen button to take a screenshot of your


game

Paste your screenshot into Word and then crop it to show


your code and annotation. Print out your work.
4

You might also like