In the previous video, we extended a game that we had originally created ourselves. But how about a game that has been built by another programmer? Can we extend such a game and how? To answer this question, we'll have a look at a Pong program. Pong is a very popular game that's considered to be classic. You can find it on the Scratch website, but we recommend you to download it from the resource page of the course website. Try it out and play it for a few minutes to see how it works. Press the green flag and using the mouse, move the paddle, so that it hits the ball. But be careful. If the ball touches the red line, the game is over.
Now let's analyze the program to see how it's been built. Let's look at the game interface first. There are two sprites: the paddle and the ball. The stage has a backdrop of a brick wall and at the bottom, there's the red line that should be avoided during the game. Now let's look at the code for the paddle. This code specifies that the horizontal coordinate x of the paddle should always be set to the one of the mouse. This means that by moving the mouse, we can move the paddle left and right without moving it up and down, as there are no instructions in this code to do that. And that's it! Now let's have a look at the code for the ball. The first thing that we notice is that there are two new blocks or balloons that are yellow colored. These contain explanations related to the program and they're called "comments". It is good practice to add comments to your code, as they can remind you what the different parts of the program do. And they're particularly useful when sharing or building games together with your friends. Comments are part of the so-called technical documentation and they're meant to be only for programmers. Scratch simply ignores them. Just by looking at the script area, we can tell that the code for the ball has two parts. At the top, we have a script that makes the ball bounce all the time, while at the bottom, we have a script that specifies what happens when the ball touches the paddle or the red line. Lets create a comment for this. So we'll right-click, select add comment and type our explanation for this script.
Let's look at this program part in more detail. It is always checking two conditions, one after the other. The first one is related to whether the ball is touching the paddle and if this is true, then a sound is played, the ball turns and it moves. The second condition is about whether the ball is touching the red bar at the bottom. In this case, a stop all block is executed, which stops all the scripts of the program and thus ends the game. Now let's analyze further the script at the top. This one specifies the initialization of the game. In other words, where the ball should be at the very beginning and which direction it should be pointing to. And it also ensures that the ball bounces every time it touches an edge of the stage and keeps moving. We'll add a comment to indicate this.
Great! We've analyzed a program for a Pong game that was built by a different programmer. We've understood it and we've added comments. In the next video, we'll start modifying and extending the game.