SWL+Lesson+7+Understanding+the+Pong+Game

=Scratch Lesson 7: Understanding the Pong Game= In this lesson, we will modify a sample game named “Pong”. We will add score, levels, and more balls to the game. To open the “Pong” game, click “Open” and browse to Projects->Games, and then select “Pong”. Click OK to open the Pong project. 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. 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. 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. ||
 * < [[image:https://lh5.googleusercontent.com/jiFcju6t7hdlqcThjJcrqZtpbTARVILNPcPcGzkPYIZ7W7o-pSpTP-QGux373Bs4E23_Y8oP-ghQTOJHsbogwhiJ1-3eEtbXz7rxwbqmQueC7RnmBc8 width="304" height="516"]]* ||< 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.

The image below shows how a sprite moves in the Scratch stage which is based on the X-Y coordinate system. This sprite moves according to this script:


 * < 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. ||
 * < [[image:https://lh6.googleusercontent.com/xx4KNw9M4rs5vf7Yr3pczzF6Qf7Wn_E2a4sKmNiyPrHse-vVLPCGOD1zmP7A3dM0x1y50x6TptoMw_WRMFD-1PadTvWo8uQeMHQIdLT1QhThirpdxbg width="222" height="131"]]*[[image:https://lh4.googleusercontent.com/g-j3LIDIg9pC5jcAuA1by7jdkcEQT7PDfkNCebXyXMU57j7KAR9DIkQOv1i3bvBD41hMFh_0Gmtz1M0ctXVyq1KBE8Nr7Xpx3WGpjkHCASSR--ZZF2w width="239" height="181"]] ||< [[image:https://lh3.googleusercontent.com/DdedoBi1zLiMCNIr7EiXBUXfFimJYFXmmPZhvTjVCQ4rzAdv_a3iMJZ1U-u6dr-VGb_qMRSE36eMmzSn9_tZWbBR8Gh1ybLmxp_JZ4l1BE7glHgj7HA width="202" height="130"]]*[[image:https://lh6.googleusercontent.com/tuM6Dq_D7cM2M9H2JJ1JU4cL9j_kPXwbTRzQQ8ZQFCtx4HTvgZQo6mNaEowG3X3Omf2E_fXaQv3MnZFI1NO_kG4tL6dKlySo5HzIeYVMF00TMv5gbAQ width="239" height="181"]] ||


 * < The combo block shown is activated when the ball hits the paddle. ||<  ||
 * < [[image:https://lh6.googleusercontent.com/g7Er1YdUCI1x7JfAauuEB8-ghX8mYKo1MtHJUQsBr6K64KhSLWaiZUhnlP-lm2cS3IsNZeHVYT0MClLUO2H8RPbvEAFSLo94Bug7kulLlboy19mdFx8 width="298" height="197"]] ||<  ||
 * < [[image:https://lh4.googleusercontent.com/EoVMh1t0KVz2imUsfqjlPFalhYro6lWlZ_h7Bt9hBpW5uPTkd9xEstLW-FAqmy4uDRao15TjAjm2HROGvmIqGzTk-gpvO7QYZPRTmvxO1dNGRdtMwNU width="238" height="173"]]* ||< [[image:https://lh4.googleusercontent.com/qT1pRpGKerXGRIxSIE_aKRZAzWCu2wo97dwrTewBoshVchp0Jo1_lpqmsBkwW_WyYU1U2jKXphkfcrGmrD5KytcLEPnFVYaEg-PfZ7DsnvFgom3OisU width="238" height="184"]]* ||

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. Also, you can make the ball leave trace of its movement by using the Pen Tool Kit.

= Link to Lesson 8 =