Module 4 Build a Game Game On 2 Game Instructions 3 Exercises 12 Look at Me 13 Exercises 15 I Can t Hear You! 17 Exercise 20 End of Module Quiz 20 2013 Lero
Game On Design a Game When you start a programming project it is a good idea to brainstorm away from the computer. Lets start with a simple computer game. It has 2 characters and a backdrop. Fill in the worksheet to get inspiration and ideas for your game. Read through the design features carefully to understand how to play the game before you get it working in Scratch. 1. Description of your Good Guy Character 2. Description of your Bad Guy Character 3. Description of the Backdrop you would like to use for your game 4. Game controls. Describe a special action that you can program for the spacebar key (E.g. jump, make Sprite disappear). Key Used Up Arrow Down Arrow Left Arrow Right Arrow Space Bar Movement Move Up Move Down Move Left Move Right 2 Scratch Workbook
Game Instructions 1. Start by introducing the 2 characters to the game. It is useful to give your sprites meaningful names. 2. Add a backdrop to the game. Don t forget to use the ideas from your design on the previous page Module 4 3
3. Select the Good Guy in the sprite selection area. 4. Program the Good Guy to move using the arrow keys. 5. Program the Bad Guy to move randomly. 4 Scratch Workbook
6. We want something to happen in our game when the Good Guy touches the Bad Guy. To trigger this we need to use a conditional statement called an if statement. As the Good Guy will be impacted when the collision occurs we will select the Good Guy and add a script for him. 7. Add a conditional statement that causes a reaction when the Good Guy senses the Bad Guy touching him. Module 4 5
8. Program the behaviour that occurs when the 2 characters touch. See a possible set of behaviours below. 9. We are going to create a variable to store a value that changes during the game. This variable tracks the number of lives remaining for the Good Guy. 6 Scratch Workbook
10. It is time to include the variable in the Good Guy script. When the game is started the number of lives will be set (initialised) to 5. A conditional statement was used to track every time the Bad Guy touches the Good Guy. Include a line in this script to decrease the number of lives by one when the sprites collide. 11. Next program the Good Guy to broadcast a message saying Game Over if the number of lives is equal to zero. Module 4 7
12. Program both sprites to disappear when the Game Over broadcast message is received. 13. Program the backdrop of the stage to change when the Game Over broadcast message is received. 8 Scratch Workbook
14. Test out the game by running it until the game is over. Does anything strange happen when the green flag is clicked again to restart the game? We need to program the Good Guy and Bad Guy to reappear when the green flag is clicked using the show command. The backdrop needs to be reset too. Module 4 9
15. You will now change what the Good Guy says when he touches the Bad Guy. He will say something different or random each time. To do this we will use Lists, which can be found under the Data blocks category in Scratch. 16. To add to the list, click on the + button at the bottom left of the list. The length will increase by one each time you add to the list, as shown. Add 4 things the Good Guy will say when touched by the Bad Guy. 10 Scratch Workbook
17. Next program the Good Guy sprite to say any of the items on the Things to say list, if he is touching the Bad Guy sprite. 18. If you do not wish the list monitor to be visible on stage you can uncheck the box next to Things to say as shown in the following image. Module 4 11
Exercises Testing is very important to ensure the game is working correctly. Run the tests outlined below to test the functionality of your game. Game Feature Bad Guy moves randomly so the Good Guy can t guess where he is going. The Good Guy starts the game with 5 lives. If the Good Guy is touching Bad Guy then the Good Guy loses a life. If the Good Guy s lives become equal to zero the game stops and a Game Over backdrop appears. When the Game restarts the background is reset and the lives are initialised back to 5. Working? Improvements. Describe what improvements you would make to the game Create version 2 of the game that has the new features below included. Enhance the Good Guy functionality by including a costume change when moving in different directions. When the spacebar key is hit make the Good Guy character jump up in the air. Alter the random movement of the Bad Guy to make the speed and motion appear as realistic as possible. Develop a scoring system for the game and a way of winning or losing at the end of the game. Introduce levels to the game. The speed and movement of the Bad Guy increases as the levels progress. Add a list of things for the Bad Guy to say if touching the Good Guy. 12 Scratch Workbook
Look at Me 1 Computer screens are divided up into a grid of small dots called pixels. The word pixel is a derived from picture element. On a black and white screen, each pixel is either black or white. As computers can only really store numbers there needs to be a way that a computer can understand how to use a set of numbers stored in a file in a way to display them as an image on the screen. This shows a picture of a letter a that has been magnified so that the dots are visible. When a computer stores the picture, all that it needs to store is which dots are black and which are white. The first line consists of one white pixel, then three black, then one white. Thus the first line is represented as 1, 3, 1. Note: The first number always relates to the number of white pixels. If the first pixel is black the line will begin with a zero. Now that you understand how a basic black and white image is stored think about the amount of data required to store an image with thousands of different colour combinations. 1 Based on Computer Science Unplugged Activity 02 Image Representation http://csunplugged.com Module 4 13
We are going to examine compression, which decreases the file size of images so they can be stored and transmitted more efficiently. Compression involves minimizing the size in bytes of a graphics file or image file. Three common file compression formats used for images are JPEG, GIF and PNG. JPEG The Joint Photographic Experts Group works best for: Compressing high-quality images such as photographs and detailed artwork, without sacrificing quality. Handling subtle shading and colour blends more efficiently. GIF The Graphics Interchange Format works best for Images with solid areas of colour Line drawings or logos Transparency effect Animation PNG The Portable Network Graphics works best for Open Source, no licence required by developers, unlike GIFs. Widely supported by the Web. Will never completely replace GIF, as it does not support animation. Scratch and Graphics Scratch accepts the following file formats for images or photos: JPG, BMP (Bitmap image files are not compressed), PNG, and GIF (including animated GIF). 14 Scratch Workbook
Exercises Use the instructions below to draw three pictures in the boxes below. Use the numbers to colour in the squares for each picture. There is a row of numbers for each line in the pictures. For example the line 4, 9, 2, 1 means you leave 4 squares empty, colour in the next 9, leave 2 empty and colour in the next 1. Remember 0 at the start means there are no white pixels at the start of the line. This means the line will start with black pixels. Module 4 15
Now that you know how numbers can represent pictures, why not make your own coded picture for a friend. Draw your pictures in the grids and when you have finished, write the code numbers beside the grids. You do not have to use the whole grid. Just leave some blank lines at the bottom if your picture does not take up the whole grid. 16 Scratch Workbook
I Can t Hear You! Sound formats in Scratch Scratch can read MP3 files and uncompressed WAV, AIF, and AU files. Just like images, sounds can also be compressed to make them smaller in size. MP3 files are an example of this. So what s it all about?... Uncompressed sound files: AIF files Gold standard of audio files, Highest-of-high-quality uncompressed audio that you can save on a disc. AIF files sound great, but files are huge. WAV file, or waveform audio file Known as simply.wav after its extension. A common type of sound file. Can also be quite large. AU file An audio file typically created on a Sun Microsystems or Unix-based machine. Not that common and quite large. Compressed sounds - MP3 MP3 files contain music and other audio. They are popular because they compress music down to a very small size while maintaining quality. Files are small, making MP3s ideal for ipods and for the internet. And now over to you Go to the website http://www.pacdv.com/sounds All sounds are in mp3 or wav formats suitable for use in Scratch. Choose a sound effect you would like to add to your project in Scratch by following instructions on the next page. Module 4 17
Using Scratch with a sound that you have downloaded to your computer Here is a sample script that you could use for this sound 18 Scratch Workbook
Using Scratch to record your own sounds It is easy to give your sou Module 4 19
Exercise Add sound effects to the game that you made earlier in this module. You could include background music for the game, sound effects when the Good Guy touches the Bad Guy and when the game is over. End of Module Quiz The first step of creating a new game is A. Design B. Test C. Debug D. Program What will happen when the Ghost touches a cactus in the script shown below 20 Scratch Workbook
A feature in Scratch that sends a message to all sprites, then continues with the next block without waiting for the triggered scripts is known as A. Wait B. Broadcast C. If D. When Which one of the images below matches the output when the script is run on the list below? Decreasing the file size of images so they can be stored and transmitted more efficiently is known as A. Depression B. Compression C. Pixilation D. Reduction What is the most suitable format for storing a high quality photographic image A. GIF B. JPEG C. PNG D. TIFF Which one of these audio file formats is most suitable for use in Scratch A. AIF B. AU C. MP3 D. MPEG Module 4 21