Starter
Scratch Pong Game Tutorial
Starter – have a go at the finished product to see what you will be making today!
Tutorial Video
Tutorial Video
Sprites & Background
Creating the sprites and background
Before we can start adding the blocks we needed in our Scratch pong game tutorial, we are going to need to create some sprites and add some costumes. So load up scratch and create a new game!
For our game we are going to need:
- 1 Player Bat Sprite
- 1 Computer (AI) Bat Sprite
- 1 Ball Sprite
- 2 Score sprites
Sprites to paint
You need to create the following spites using the paint brush option:
Sprites to get from the library
You need to get the zero sprite from the library.
Once you have got the zero sprite, you need to add more costumes until it has all the costumes needed, as seen below.
Duplicate your number sprite
Once you have created one number sprite, don’t do the whole process twice, just right click on your sprite (in the sprites area) and select ‘duplicate’.
Player Bat
Player Bat Code
Our player bat code is nice and simple, is just has one job:
- When the player moves the mouse, set the bat’s Y coordinate to the same as the mouse’s Y coordinate.
Computer bat
Computer Bat Code
The computer bat’s code is also nice and simple. It only has one job:
- If the bally is higher up than the computer paddle, move the paddle up
- If the ball is lower down than the computer paddle, move the paddle down.
Ball
Ball Code
The ball’s code is move complicate, in fact it pretty much runs most of the game:
- Start in the middle of the screen
- Turn in a random direction
- If it hits the edge, bounce.
- If it hits a paddle bounce
- If it goes past a bat (x coordinate of less than -230(computer wins the round) or greater than 230 (player wins the round)
- Every time it hits a paddle, increase the ball speed by one to make the game get steadily harder
Scores
Score Counters Code
The score sprites have an easy life, they just do:
- At the start of the game set their costume(and therefore the score) to 0-pixel
- When the player/computer scores, change the costume to the next costume (increasing the displayed score by one)
Improvements
Improvements
Now that you have finished the Scratch pong game tutorial, you can start to add your own improvements to the game. Here are some suggestions to challenge your Scratching skills!
- Can you adapt the game so that it is a 2 player game?
- Can you add a start & game over screen
- Can you think of your own improvements?