Scratch: Lesson 5

Powerpoint for Teacher Use

In this lesson, you will learn how to make a version of the famous game Pong. Pong was one of the earliest arcade games, the first sports arcade game, and the first commercially successful games. Its success helped launch the first home console and establish the video game industry as a whole.

In the original Pong, the player controlled a white paddle and tried to hit a small white ball back to a computer controlled white paddle. In our modern version, you will be playing against yourself while trying to keep your ball from falling into the lava.

You will learn how to:

  • Use the “Operators” Tab
  • Use the “Data” Tab
  • Use the “Sensing” Tab

Step 1: Creating Sprites and Background

In this tutorial, you will need two sprites and a background.

You will need a sprite that will act  as your “Ball”

  • Add a Sprite
    • Delete the Cat Sprite by right clicking on the sprite and selecting “delete”
    • Choose any sprite you want. (The more round it is the better)
      • Click on the creature’s head underneath the stage.
      • Select any sprite and use the shrink tool shrink to make it small enough for it to easily bounce around the screen.

You will also need a paddle.

  • Make a new sprite
    • Click on the paint brush paintbrush highlightsquarefill
    • Click on the black rectangle to the left of the canvas.
    • Click the filled black rectangle
    • Click and drag on the canvas to create a thin rectangle.
  • On the stage the rectangle should appear. Drag it so that it is near the bottom of the screen.

And a Background to your game. In our version of Pong the game ends when the ball hits the lava so our background will need to contain a lava pit.

  • Make the Background makethebackground2.PNG
    • Click on the Stage button at the bottom left hand corner.
    • Click on the “Backdrops” Tab
    • Click on the black rectangle.
    • Click the filled rectangle.
    • Change the color to red (or whatever color you choose).
    • Draw a thin rectangle along the bottom.
makethebackground1

 

 

 

Step 2: Programming Pong

First Programming Block

The first block that we are going to program sets up a new game every time the player presses the .

  1. From the  tab grab the . Most of the time every block you program in Scratch will start with this button.
  2. From the  tab grab the switchbackdropto. This will switch the backdrop to the backdrop we just created when the game starts.
  3. From the  tab grab the gotoxy. This will make your ball start in the middle of the screen when the game starts.
  4. First go to the  tab and click on makeavariable and then name that Variable “Score” and press OK. NewVariable
  5. Then grab the showvariablescore and the setscoreto0. This will make the Score show on the stage and set it to 0 when the game starts.
  6. From the  tab grab the waituntil. This will make the program wait until a certain condition is fulfilled before it continues.
  7. From the sensing tab grab the touchingcolor. Click on the colored square and then click on the rectangle at the bottom of your stage to change the color in the square to the color at the bottom of the stage.
  8. Drag the touchingcolor into the dark diamond in the waituntil block. This will make the program wait until the ball sprite is touching red (Or what ever color you made your lava.)
Your first block of code should look like this:
programmingblock1

Second Programming Block

The programming block will control what happens when the ball hits the paddle.

  1. Now think about what goes at the beginning of each programming block. If you thought of the  then you are correct.
  2. Now from the  tab grab the  and put it underneath the . Then grab the ifthen and put it inside of the  .

    The ifthen loop controls under what condition something happens, then it preforms whatever program you have put inside of it once that condition is met.

  3. From the sensing tab grab the touching and put it inside of the dark diamond inside of the ifthen.  Press the black triangle and click on “Sprite-2” to select your paddle sprite.
  4. From the sound tab grab the playsound and place it inside of the ifthen.
  5. Now go to the  tab and get the pointindirection block
  6. From the Operators tab get the subtraction.PNG and place it inside of the white bubble next to the “point in direction.” It should look like this pointindirectionandsubtraction.
  7. In the first bubble type “180.” In the second bubble place the direction button from the  tab inside of it, by dragging it over the second bubble until the bubble highlights in white.

    What the directionplus180 does is take the angle that the ball hits the paddle, say 45 degrees, and then subtracts that angle from 180. 180 180is a  straight line along the x-axis, when we subtract the angle that the ball enter from, 45 degrees, from 180 degrees we get 135 degrees. That is the angle that the ball will exit from when it hits the paddle.

    45degrees                 135

  8. From the  tab grab the changescoreby1. This will change the score by one point when you successfully deflect the ball with your paddle.
  9. From the  tab grab the move5steps , this gives the ball an extra boost when it hit the paddle so it doesn’t get stuck.
  10. From the  tab grab the  then go to the Operators tab and grab the . Place it inside of the white bubblepickrandominsideofturn, change the first white bubble to -45 and the second white bubble to 45. turnwithpickrandom

Your second block should look like this:

blocktwo

Third Programming Block

The block will control the random direction that your ball goes in when the game starts and controls the speed of your ball.

  1. From the  tab grab the .
  2. From the Operators tab get the  and place it inside of the white bubble next to the “point in direction.” It should look like this pointindirection.
  3. In the first bubble type “0,” in the second bubble type “360.” pointindirection1

    The reason that it picks a random number from 0 to 360 is because a circle is 360 degrees around. This means that the ball will go in any random direction when the game starts.

  4. Now from the  tab grab the  and put it underneath the pointindirection1.
  5. Inside of the  place the move5steps and the . You can change the number inside of the move5steps to increase or decrease the speed.

Your third block should look like this:

blockthree

Fourth Programming Block

  1. From the  tab grab the .
  2. From the  tab grab the  and place it underneath the .
  3. Inside of the  place the move5steps and the .

Your fourth block should look like this:

fourthblock

Making a Second Backdrop

  1. Click on the Stage button at the bottom left hand corner.
  2. Click on the “Backdrops” Tab
  3. Make a “Game Over” Screen

Fifth Programming Block

  1. From the  tab grab the
  2. From the  tab grab the  and place it underneath the .
  3. Inside of the  place a ifthen
  4. Go to sensing and get thetouchingcolor place it inside of the diamond in the  ifthen.
    block5step4th
  5. From the  tab, get the switchthebackdrop and place it inside of block5step6.

Your fifth block should look like this:

block5

Step 3: Programming the Paddle

  1. Click on the paddle sprite paddle
  2. Go to  and drag two whenspacepressed on to the code table.
  3. Change the “space” to “right arrow” whenrightarrowpriced for one of the blocks. For the other change it to “left arrow.”
  4. From the  tab drag two changexby on to the code table.
  5. Connect one changexby to both whenspacepressed1.
  6. Under the whenleftpressed change the changexby to changexby-10 .

Your final blocks should look like:

block6

Advertisements