Pong
The original Classic Arcade Game.
There is no cool way to
chase after a bouncing ping-pong ball.
Start a new project. Name your game.
Delete the cat sprite.
Use this sprite: here
Duplicate the sprite, twice. (pongSprite)
After you open the link, click this icon (top-right) to download.
In Scratch, you will need to Choose a Sprite and then upload this file
(the blue cat icon on the bottom right)
Name one sprite → ball
Name the other sprite → paddleOne
Name the third sprite → paddleTwo
NOTE:
Sprite names, Costume names, and variable names, should all start with a lowercase letter.
If a name has more than one word, then the first letter of each subsequent word is capitalised.
This is called camelCase, and it is an Industry accepted standard for naming conventions.
Check
Do you have 3 sprites. Are the named: ball, paddleOne, paddleTwo?
[code]
paddleOne
Note: you do NOT need to type in the “comments” (yellow textbox), these are provided as way of explanation as to the how & why of the code.
[code]
paddleTwo
These differ from paddleOne
Note:
“Comments” for this code can be seen on the previous sprite.
There are two slides for the ball code
You will need to append and/or alter the code as per the directions. (grey text)
The first slide offers the format of the control blocks within the code.
[code]
ball
Randomises the balls starting direction
There are FOUR If-Then conditions within this sprite, they control:
The maximum speed of the ball.
The ball bouncing off either paddle.
PlayerTwo scoring a point.
PlayerOne scoring a point.
The code for each of these is on the next slide, you will need to append this code accordingly.
Be careful and check that each block is NOT inside another.
[code]
ball
This code limits the ballSpeed
This code goes under the IF-THEN (touching paddle), but inside the FOREVER
HINT: If you get stuck, see code working HERE
Can I?
append & alter the ball code to offer a more “real” game experience
A good idea
Save as a Copy, add a “v2” to the name, before continuing
?
[code]
ball
Replace this code with BOTH the options below
You will need to create the
variable: paddleOffsetY (for all sprites)