Shall We Learn

  • Increase font size
  • Default font size
  • Decrease font size

Scratch Lesson 7: The Pong Game

E-mail

To view or print the PDF copy of this lesson, click HERE.

In this lesson, we will explore a sample game named “Pong”. This game is simple so it's a good place to start learning how to create a game. To open the “Pong” game, click “Open” and browse to Projects->Games, and then select “Pong”. Click OK to open the Pong project.

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0003.png

There are two sprites: ball and paddle. The ball sprite moves randomly by its own, whereas the paddle sprite is moved by user moving the mouse.

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0004.png

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0005.png

Click the green flag to try the game. Use the paddle to hit the ball as it falls down. You should soon find that if the ball hits the bottom of the Stage, the game would end.

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0018.png

The ball sprite has three combo blocks. You can think of a sprite as a robot and each combo block as a separate motor. Just like a robot is controlled by many motors, a sprite can be controlled by many combo blocks. In Computer Science language, each combo block is a thread of execution, working independently of the other threads.

In the picture shown left, first combo block controls how the game would end - if ball touches red, then game ends.

The middle combo block checks whether the ball has touched the paddle and takes action when it does.

The last combo block checks whether the ball has hit the edge and takes action when it does.

The image below shows how a sprite moves in the Scratch stage which is based on the X-Y coordinate system.

Scratch_xy-grid.gif

This sprite moves according to this script:

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0020.png

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0023.png

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0024.png

The Combo block shown is activated when the ball hits Stage’s red bottom.

The combo block shown is activated when the ball hits the edges of the Stage.

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0030.pngC:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0028.png

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0034.pngC:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0032.png

The combo block shown is activated when the ball hits the paddle.

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0037.png

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0035.png

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0038.png

TRY THIS: Try changing the randomness by changing the value in “pick random ? to ?” block. To make it more random and the game more difficult, increase the range of the degree change.

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0039.png

Also, you can make the ball leave trace of its movement by using the Pen Tool Kit.

C:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0042.pngC:\Documents and Settings\Jessica W Chiang\My Documents\SnagIt Catalog\Image-0044.png

This concludes Lesson 7.

To view or print the PDF copy of this lesson, click HERE.


Only registered users can write comments!

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

Last Updated on Monday, 28 September 2009 10:58  

85px-Scratchcat.svg                       Java               python-logo