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. คล้ายกับวิดีโอก่อนหน้านี้ เราจะเพิ่มบล็อกสุ่มเลือก และระบุค่าระหว่าง 30 -30 วิธีนี้ เมื่อกดแถบพื้นที่ลูกบอลจะถูกวางไว้ในจุดที่เราระบุไว้ และจะชี้ในทิศทางแบบสุ่ม ลูกควรให้ย้ายจนกระทั่งมันถูกจับ โดยผู้รักษาประตู หรือจน กว่าจะถึงเป้าหมายบรรทัด ดังนั้นเราจะแนะนำซ้ำจนถึงบล็อก และเราจะตั้งเงื่อนไขของผู้รักษาประตูสัมผัส หรือสัมผัสเป้าหมายบรรทัด ซึ่ง ในกรณีของฉัน สีดำ จำไว้ว่า การ หรือบล็อกที่ช่วยให้เราแสดงเงื่อนไขที่ซับซ้อนเหมือนกับเราได้ที่นี่ ภายในควบคุมเงื่อนไขวนรอบนี้ เราจะยังคงมีให้ลูกย้าย และเด้งถ้าบนขอบ ในที่สุด เราสามารถตรวจสอบว่า การแก้ไขประตู ในกรณีนี้ เราสามารถพูดได้ "เป้าหมาย" ดังนั้น เราจะแนะนำบล็อกการถ้านั้นอื่น และตั้งเงื่อนไขของการสัมผัสสีประตู ที่ สำหรับฉัน สีดำ นอกจากนี้เรายังจะใส่บล็อกบอกว่าภายในหนึ่งตัดสินใจนี้ว่า "เป้าหมาย" แล้ว ส่วนอื่นของการตัดสินใจนี้เกี่ยวข้องกับกรณีที่ลูกถูกบันทึกไว้ โดยผู้รักษาประตู ดังนั้นเราจะบอกว่า "บันทึก" เราสามารถเพิ่มคู่ความเห็นเพื่อเตือนตัวเองสองกรณีอ้างถึง บล็อกอื่น ๆ ของรหัสที่เราได้บอลจะไม่เกี่ยวข้อง ดังนั้น เราจะลบพวกเขา เป็นการดีเพื่อรวมพื้นที่สคริปต์รหัสที่จำเป็นเพื่อให้ไม่ยุ่งเกินไป ลองทดสอบเกมของเราฉะนี้ กด space bar ดี เราสามารถควบคุมผู้รักษาประตูของเราเพื่อให้เป้าหมาย มันจะเป็นประโยชน์มากในการให้คะแนน ขวา การติดตามจำนวนของเป้าหมาย เราจำเป็นต้องมีตัวแปร เรากำหนดตัวแปรนี้ ชื่อ "เป้าหมาย" ดังที่เราเคยแล้ว เป็นการดีการเลือกชื่อพนักงาน ที่จุดเริ่มต้นของเกม จำนวนประตูควรเป็น 0 เพื่อระบุนี้ เราจะแนะนำบล็อกค่าสถานะสีเขียวตาม ด้วยบล็อกสำหรับการตั้งเป้าหมายเป็น 0 เมื่อควรเปลี่ยนค่าของตัวแปรนี้ ทุกครั้งมีประตู ดังนั้น เราจะนำเป้าหมายการเปลี่ยนแปลง โดยบล็อกภายในส่วนของเราตัดสินใจแล้ว และตั้งค่าเป็น 1 นอกเหนือจากการนับจำนวนเป้าหมาย มันยังจะน่าสนใจเพื่อติดตามรายการบันทึกไว้ เราสามารถทำได้ โดยการกำหนดตัวแปรใหม่ที่เรียกว่า "บันทึก" ค่าตั้ง 0 ที่จุดเริ่มต้นของเกม และมันเพิ่ม โดย 1 ทุกครั้งที่ลูกถูกจับ ยอดเยี่ยม! นอกจากนี้เราสำเร็จแล้วได้ขยายโป่งจะได้รับการยิงโทษเกม นอกจากนี้คุณยังสามารถเพิ่มเสียงถ้าคุณรู้สึกเช่นนั้นหรือแม้กระทั่งบางลักษณะการแสดงผล ในรอยขีดข่วน กระบวนการในการใช้โปรแกรม และทำการปรับเปลี่ยนเป็นเรียกว่าบูรณาการ หรือ remixing ตัวอย่างเช่น หากเรามองเกมปิงปองบนเว็บไซต์รอยขีดข่วน เราจะเห็นไอคอนนี้ต้นไม้ซึ่งแสดงจำนวนครั้งของเกมได้ถูกรีมิกซ์ ถ้าคุณคลิกที่มัน คุณจะเห็นรุ่นต่าง ๆ ของเกมนี้มีโครงสร้างในรูปแบบของต้นไม้ เราขอเชิญคุณเลือกดูต้นไม้ต้นนี้ และลองบางส่วนของรุ่นเหล่านี้
การแปล กรุณารอสักครู่..
