0:06
In the last unit we created a game in which we were moving a helicopter across the sky while avoiding the clouds.
0:13
Let's consider some possible extensions or additions that can make this game even more interesting and challenging.
0:19
What could we add?
0:22
One option would be to count the number of times our helicopter touches the clouds. To do this, we need a place to store this value, what we call in computer science a variable.
0:34
A variable is a space in the computer's memory where we can hold information used by our program.
0:41
Variables have a name and a value associated with them. Which we can access to use or modify.
0:47
For instance, here we've defined a variable called "name" which has value Dave
0:52
as well as an "age" variable which has value 14. You can think of variables as labeled drawers which contain a piece of information. The labels help us identify the variable that we're interested in, and we can then access it to read its value or even modify it.
1:11
Just like drawers can be for personal only or for common use, we can distinguish between local and global variables.
1:19
Local variables are for the personal use of a specific program element such as a sprite and cannot be accessed by other sprites.
1:27
On the other hand, global variables can be used by all program elements.
1:32
Variables are a fundamental concept in computer science and are very useful when developing games. For instance, to keep track of the score, the difficulty level, or the number of lives of our characters. To extend our helicopter game, we'll create a variable in Scratch.
1:49
We'll go to the Data Palette, and click on Make a Variable.
1:53
This will create a place to store the number of times the helicopter hits the clouds.
1:59
We'll give it a representative name, such as times or hits, I'll go for "hits". We'll set this variable to be global, so we'll choose for all sprites. This give us more flexibility for the future, so if later on we decide to add more sprites, they can also access and modify this variable.
2:18
When the program starts its execution, the number of hits should be zero. We can define this by using the block set hits to zero, and introducing it right after clicking the green flag.
2:33
When should this hits value change?
2:36
Every time the helicopter touches a cloud, its value should increase by one. We can do this with the use of the block change hits by one, which we'll place right after the say block.
2:50
Now, let's run the program to see how the number of hits changes with each collision.
2:55
We need to make sure that the hits variable is selected in order to make it visible on the stage.
3:03
Brilliant! We can now keep track of the number of hits! We could further extend our game to incorporate some graphic effect during collision. For example, we can use a block, change brightness effect by 25, placing it before the say block, and we can restore the helicopter's looks by introducing a clear graphic effects block later on.
3:29
We can further enrich our helicopter game to include instructions to the user. This way the user will know straight away what he's expected to do.
3:39
These instructions to the user are equivalent to the so-called user documentation that you would see in professional software systems.
3:47
User documentation typically includes tutorials and manuals which guide the user. In our case, we don't need a manual. Including instructions is enough.
3:58
We can do this by having the helicopter say these instructions for a few seconds at the very beginning of the game.
4:05
For instance, it could first say, "move me with the arrow keys".
4:17
And, then, "but avoid the clouds". Let's try it out. Good! Now how about including a restart button, which let's us start the game afresh? The idea is that the restart button would reset the number of hits to zero. How can we do this in Scratch?
4:49
We'll introduce a button sprite from the Scratch library.
4:55
This is rather big, so we'll go to the Paint editor to modify it. And click on Convert to Bitmap.
5:03
Before resizing it, we'll add some text, so that the user knows what it's meant to do. We can use the Text tool to type restart, and we'll make the text white.
5:21
We'll also make sure that the text is placed in the center of the button. Good. We'll now shrink our button.
5:58
We can also specify where to place the button when the game starts. For instance, I'll put it next to my hits counter.
6:11
Now we'll specify that when we click the button, the number of hits is set to zero. So we'll introduce a when this sprite clicked block from the Events pallet,
6:22
followed by a block to set hits to zero.
6:29
Let's test our revised helicopter game to see if it works.
6:40
Now I'll hit the Restart button. Excellent! The number of hits was reset to zero.
6:54
We invite you to try more effects and incorp
0:06ในหน่วยสุดท้ายที่เราสร้างขึ้นในเกมที่เราได้เคลื่อนย้ายเฮลิคอปเตอร์ข้ามท้องฟ้าในขณะที่หลีกเลี่ยงเมฆ0:13ลองพิจารณาที่เป็นไปได้บางส่วนขยายหรือเพิ่มเติมที่สามารถทำให้เกมนี้ยิ่งน่าสนใจและท้าทาย0:19อะไรที่เราสามารถเพิ่ม ?0:22ตัวเลือกหนึ่งจะนับจำนวนครั้งที่เฮลิคอปเตอร์ของเราสัมผัสเมฆ ทำแบบนี้ เราต้องการสถานที่เพื่อเก็บค่า สิ่งที่เราเรียกคอมพิวเตอร์ตัวแปร0:34ตัวแปรคือ พื้นที่ในหน่วยความจำของคอมพิวเตอร์ ที่เราสามารถเก็บข้อมูลการใช้โปรแกรมของเราสไตล์ตัวแปรที่มีชื่อและคุณค่าที่เกี่ยวข้องกับพวกเขา ซึ่งเราสามารถเข้าถึงการใช้หรือแก้ไข0:47ตัวอย่าง เราได้กำหนดตัวแปรที่เรียกว่า " ชื่อ " ซึ่งมีค่าเดฟ0:52เช่นเดียวกับ " อายุ " ตัวแปรซึ่งมีค่า 14 คุณสามารถคิดของตัวแปรเป็นป้ายลิ้นชักซึ่งประกอบด้วยชิ้นส่วนของข้อมูล ฉลากช่วยให้เราระบุตัวแปรที่เราสนใจ และเราสามารถเข้าถึงมันอ่านค่าของ หรือแม้กระทั่งการปรับเปลี่ยนมัน1 : 11เหมือนลิ้นชักสามารถเป็นส่วนบุคคลเท่านั้น หรือสำหรับใช้งานทั่วไป เราสามารถแยกความแตกต่างระหว่างตัวแปรท้องถิ่นและสากล1 : 19ตัวแปรท้องถิ่นสำหรับการใช้งานส่วนบุคคลของโปรแกรมเฉพาะองค์ประกอบ เช่น สไปร์ท และไม่สามารถเข้าถึงได้โดยการควบคุมอื่น ๆ1บนมืออื่น ๆ , ตัวแปรทั่วโลกสามารถใช้โดยองค์ประกอบของโปรแกรมทั้งหมด1 : 32ตัวแปรที่เป็นแนวคิดพื้นฐานในคอมพิวเตอร์ และจะมีประโยชน์มากเมื่อมีการพัฒนาเกม ตัวอย่างเช่น ในการติดตามของคะแนน , ระดับความยาก , หรือหมายเลขของชีวิตของตัวละครของเรา ขยายเกมเฮลิคอปเตอร์ของเรา เราจะสร้าง ตัวแปรในการเริ่มต้น1:49เราจะไปหาข้อมูลสี และคลิกให้ตัวแปรเป่านี้จะสร้างสถานที่เก็บจำนวนครั้งที่เฮลิคอปเตอร์ชมเมฆ1:59เราจะให้ตัวแทนชื่อ เช่น เวลา หรือ ฮิต ฉันจะ " ฮิต " เราจะตั้งค่าตัวแปรนี้เป็นสากล ดังนั้นเราจะเลือกสำหรับสไปรต์ นี้ให้ความยืดหยุ่นมากขึ้นสำหรับอนาคต ดังนั้น หากภายหลังเราตัดสินใจที่จะเพิ่ม sprites เพิ่มเติม พวกเขายังสามารถเข้าถึงและแก้ไขตัวแปรนี้2 : 18เมื่อคุณเริ่มต้นโปรแกรมการปฏิบัติของตน จำนวนฮิตควรจะเป็นศูนย์ เราสามารถกำหนดได้ โดยการใช้ชุดบล็อกนิยมศูนย์ และแนะนำมันขวาหลังจากคลิกธงเขียว2 : 33เมื่อควรนี้ฮิตค่าเปลี่ยน2 : 36ทุกครั้งที่เฮลิคอปเตอร์สัมผัสเมฆ มูลค่าของมันจะเพิ่มขึ้นโดย 1 เราสามารถทำมันได้ด้วยการเปลี่ยนบล็อกฮิตโดยหนึ่งซึ่งเราจะวางหลังจากพูดบล็อก2 : 50ตอนนี้ ลองรันโปรแกรมเพื่อดูว่าจำนวนครั้งการเปลี่ยนแปลงแต่ละชน .2:55เราต้องให้แน่ใจว่าฮิตตัวแปรที่เลือกเพื่อที่จะให้มันแสดงบนเวที3:03สุดยอด ! ตอนนี้เราสามารถติดตามจำนวนของผู้ชม ! เราสามารถเพิ่มเติมขยายเกมของเราที่จะรวมบางผลกราฟิกในระหว่างการปะทะกัน ตัวอย่างเช่น เราสามารถใช้บล็อกเปลี่ยนผลความสว่าง 25 วางมันก่อนว่า บล็อก และเราสามารถเรียกคืนลักษณะของเฮลิคอปเตอร์โดยอาศัยลักษณะพิเศษกราฟิกที่ชัดเจนป้องกันในภายหลัง3 : 29เราสามารถเพิ่มเกมเฮลิคอปเตอร์ของเราที่จะรวมคำแนะนำให้กับผู้ใช้ วิธีนี้ผู้ใช้จะรู้ได้ทันทีว่าเขากำลังคิดจะทำ3:39แนะนําให้ผู้ใช้เหล่านี้จะเทียบเท่ากับที่เรียกว่า เอกสารของผู้ใช้ที่คุณจะเห็นในระบบซอฟต์แวร์มืออาชีพ3:47เอกสารที่ผู้ใช้มักจะมีแบบฝึกหัดและคู่มือซึ่งคู่มือผู้ใช้ ในกรณีของเรา , เราไม่ต้องใช้คู่มือ รวมทั้งใช้เป็นพอ3:58เราสามารถทำเช่นนี้ โดยมีเฮลิคอปเตอร์พูดคำแนะนำไม่กี่วินาทีที่จุดเริ่มต้นของเกม04 : 05ตัวอย่างเช่นมันสามารถพูดก่อนว่า " ผมย้ายด้วยปุ่มลูกศร "4 : 17และ , แล้ว , แต่หลีกเลี่ยงเมฆ " มาลองกันเถอะ ดี ! ตอนนี้วิธีการเกี่ยวกับรวมถึงปุ่มเริ่ม ซึ่งเรามาเริ่มเกมใหม่ได้หรือ ความคิดคือว่าปุ่มเริ่มจะตั้งค่าจำนวนของผู้ชมเป็นศูนย์ วิธีที่เราสามารถทำเช่นนี้ในการเริ่มต้น ?การสร้างเราจะแนะนำปุ่มภาพจากรอยขีดข่วน ห้องสมุด4:55นี้จะค่อนข้างใหญ่ ดังนั้นเราจะไปทาสี Editor เพื่อแก้ไขมัน และคลิกที่แปลงเป็นบิตแมป5:03ก่อนการปรับขนาดได้ เราก็จะเพิ่มข้อความบางส่วนเพื่อให้ผู้ใช้รู้ว่าสิ่งที่มันหมายถึงการทำ เราสามารถใช้ข้อความเครื่องมือชนิดใหม่ และเราก็จะได้ข้อความสีขาว5 : 21เรายังจะให้แน่ใจว่าข้อความจะถูกวางไว้ในศูนย์กลางของปุ่ม ดี ตอนนี้เราจะปุ่มของเราหด5:58เราสามารถระบุตำแหน่งการวางปุ่มเมื่อเริ่มเกม ตัวอย่าง ผมจะวางติดกับเคาน์เตอร์ฮิตของฉัน6 : 11ตอนนี้เราก็จะระบุว่า เมื่อเราคลิกปุ่ม จำนวนของผู้ชมมีการตั้งค่าศูนย์ ดังนั้นเราขอแนะนำเมื่อสไปรท์นี้คลิกบล็อกจากเหตุการณ์แท่นวางสินค้า6 : 22ตามด้วยชุดฮิตบล็อกศูนย์6 : 29ลองทดสอบของเราปรับปรุงเฮลิคอปเตอร์เกมเพื่อดูว่ามันทำงานอย่างไร6 : 40ตอนนี้ผมจะกดปุ่มรีสตาร์ท . ที่ยอดเยี่ยม ! จำนวนของผู้ชมถูกตั้งค่าเป็นศูนย์6:54เราขอเชิญชวนให้คุณลอง incorp ผลกระทบมากขึ้น
การแปล กรุณารอสักครู่..
