Just like we transformed the Pong game into Pizza Pong, we can modify it to turn into a game for throwing penalty kicks. Do you want to give it a go? Let's do it!
We'll open the project for the original Pong game in Scratch and we'll replace the paddle costume with a goalkeeper viewed from above.
We'll draw the costume ourselves. I'll go for a simple drawing, where we have circles for the goalie's head and hands, and lines for his arms.
We'll reposition the sprite on the stage, and name it accordingly.
We'll also replace the ball costume with a football costume, which we can find in the library.
The last element that we need to change in the game interface, is the stage backdrop.
We want it to look like a football field, which we'll draw ourselves. So we'll color it green and we'll specify the point from where the penalties will be shot.
Remember to mark the bottom edge with a different color, such as black, to indicate the goal line.
Make sure that this color is different from the grass and the goalkeeper.
The code for the goalkeeper is good as it is, but we'll need to modify the code for the ball.
In order to make it easier to shoot many penalties, we'll replace the block with the green flag with a block for when space key pressed. We also need to modify the direction in which the ball is pointing. Otherwise, the penalties will always be shot in the same way.
Similarly to the previous video, we'll add a pick random block and specify values between -30 and 30. This way, when the space bar is pressed the ball will be placed in the spot that we indicated, and it will be pointing in a random direction.
The ball should keep moving until it is caught by the goalkeeper or until it reaches the goal line. So we'll introduce a repeat until block and we'll set its condition to be touching goalkeeper or touching the goal line, which, in my case, is colored black.
Remember that the or block lets us express complex conditions like the one we have here.
Inside this condition-controlled loop, we'll still have that the ball moves and bounces if on edge.
Finally, we can check whether a goal was scored, in which case, we can say "goal".
So we'll introduce an if-then-else block and set its condition to touching the goal line color, which, for me, is black.
We'll also put a say block inside the then part of this decision to say "goal".
The else part of this decision involves the case where the ball is saved by the goalkeeper, so we'll say "saved". We can add a couple of comments here to remind ourselves what these two cases refer to.
The other blocks of code that we had for the ball are no longer relevant. So, we'll delete them. It is good practice to include on the script area only the code that is needed so that it's not too messy. Let's test our game so far, pressing the space bar.
Nice! We can control our goalie to keep goal.
It would be very useful to keep the score, right?
To keep track of the number of goals, we need a variable. We define this variable, naming it "goals".
As we've already noted, it is good practice to choose representative names.
At the beginning of the game, the number of goals should be 0. To specify this, we'll introduce the green flag block followed by a block for setting goals to 0.
When should the value of this variable change? Every time a goal is scored. So we'll put a change goals by block inside the then part of our decision and set it to 1.
Apart from counting the number of goals, it would also be interesting to keep track of the saved ones. We can do this by defining a new variable called "saved".
Its value is also 0 at the beginning of the game. And it increases by 1, every time the ball is caught.
Excellent! We've successfully extended Pong to get a penalty shoot out game. You can also add sounds if you feel like it or even some visual effects.
In Scratch, the process of taking a program and making modifications is called reinventing or remixing.
For example, if we look at the Pong game on the Scratch website, we'll see this tree icon which shows the number of times the game has been remixed.
If you click on it, you'll see the different versions of this game structured in the form of a tree. We invite you to browse this tree and try some of these versions.
Just like we transformed the Pong game into Pizza Pong, we can modify it to turn into a game for throwing penalty kicks. Do you want to give it a go? Let's do it! We'll open the project for the original Pong game in Scratch and we'll replace the paddle costume with a goalkeeper viewed from above. We'll draw the costume ourselves. I'll go for a simple drawing, where we have circles for the goalie's head and hands, and lines for his arms. We'll reposition the sprite on the stage, and name it accordingly. We'll also replace the ball costume with a football costume, which we can find in the library. The last element that we need to change in the game interface, is the stage backdrop. We want it to look like a football field, which we'll draw ourselves. So we'll color it green and we'll specify the point from where the penalties will be shot. Remember to mark the bottom edge with a different color, such as black, to indicate the goal line. Make sure that this color is different from the grass and the goalkeeper. The code for the goalkeeper is good as it is, but we'll need to modify the code for the ball. In order to make it easier to shoot many penalties, we'll replace the block with the green flag with a block for when space key pressed. We also need to modify the direction in which the ball is pointing. Otherwise, the penalties will always be shot in the same way. Similarly to the previous video, we'll add a pick random block and specify values between -30 and 30. This way, when the space bar is pressed the ball will be placed in the spot that we indicated, and it will be pointing in a random direction. The ball should keep moving until it is caught by the goalkeeper or until it reaches the goal line. So we'll introduce a repeat until block and we'll set its condition to be touching goalkeeper or touching the goal line, which, in my case, is colored black. Remember that the or block lets us express complex conditions like the one we have here. Inside this condition-controlled loop, we'll still have that the ball moves and bounces if on edge. Finally, we can check whether a goal was scored, in which case, we can say "goal". So we'll introduce an if-then-else block and set its condition to touching the goal line color, which, for me, is black. We'll also put a say block inside the then part of this decision to say "goal". The else part of this decision involves the case where the ball is saved by the goalkeeper, so we'll say "saved". We can add a couple of comments here to remind ourselves what these two cases refer to. The other blocks of code that we had for the ball are no longer relevant. So, we'll delete them. It is good practice to include on the script area only the code that is needed so that it's not too messy. Let's test our game so far, pressing the space bar. Nice! We can control our goalie to keep goal. It would be very useful to keep the score, right? To keep track of the number of goals, we need a variable. We define this variable, naming it "goals". As we've already noted, it is good practice to choose representative names. At the beginning of the game, the number of goals should be 0. To specify this, we'll introduce the green flag block followed by a block for setting goals to 0. When should the value of this variable change? Every time a goal is scored. So we'll put a change goals by block inside the then part of our decision and set it to 1. Apart from counting the number of goals, it would also be interesting to keep track of the saved ones. We can do this by defining a new variable called "saved". Its value is also 0 at the beginning of the game. And it increases by 1, every time the ball is caught. Excellent! We've successfully extended Pong to get a penalty shoot out game. You can also add sounds if you feel like it or even some visual effects. In Scratch, the process of taking a program and making modifications is called reinventing or remixing. For example, if we look at the Pong game on the Scratch website, we'll see this tree icon which shows the number of times the game has been remixed. If you click on it, you'll see the different versions of this game structured in the form of a tree. We invite you to browse this tree and try some of these versions.
การแปล กรุณารอสักครู่..
