Download as pdf
Download as pdf
You are on page 1of 15
4187126, 11.08 aM Rock band Rock band Learn how to code your own musical instruments Step1 Introduction Leam how to code your own musical instruments! What you, ill make ‘Youwill make a game where you can elick on the singer or the drum to hear singing or drum sounds. + Use code to change a sprite's costume in Scratch + Use code to make sprites react to input in Scratch + Add sounds to a sprite in Scratch + Acomputer capable of running Scratch 3 Software * Scratch 3 {either online (https: //rpf.io/scratchon) or offline (https://rpfio/scratchoff)) nipsifprojectsraspberrypiorgleniprojectsrock bandiprint ans: 4187126, 11.08 aM Rock band © asttonatinsrmationoredustr ‘You can find the completed project here (inttps://rpfio/p/en/rock-band-get), nipsifprojectsraspberrypiorgleniprojectsrock bandiprint ans 4187126, 11.08 aM Rock band Step2 Sprites Before you can start coding, you'll need to add in a ‘thing’ to code. in Scratch. these ‘things’ are called sprites. Open a new Scratch project. Online: open a new online Scratch project at rpfiio/scratch-new (http://rpfio/scratch-new), Offline: open a new project in the offline editor. If youneedto download and install the Scratch offine editor, you can findit at rpf.io/scratchoff (httn:// tpfio/seratchoff), It looks like this: ‘The cat sprite that you can see is the Scratch mascot. You don't need it for this game, so get rid of it by clicking on the X in the comer. nipsifprojectsraspberrypiorgleniprojectsrock bandiprint 3s 4187126, 11.08 aM Rock band Next, click on Choose sprite from library to open up a list of all the Scratch sprites. —i Scroll down until you see 2 drum sprite, Click on a crum to add it to your project. _— 2 Drum Drum Kit Ifyou are signed in to your Seratch account, type the title of your project into the project title box at the top of the screen: Tip: Give your projects helpful names so that you can easily ind them when you have lots of projects. Next, click on File, and then on Save now to save your project, If you are not online or don’t have a Soratch account, you can save a copy of your project by clicking on Save to your computer instead. nipsifprojectsraspberrypiorgleniprojectsrock bandiprint ans 4187126, 11.08 aM Rock band Step3 The Stage ‘The Stageis the area on the right, and is where your project comes to life. Think of it as a performance area, just lke areal stagel At the moment, the stage is white and looks pretty boring! Add a backdrop to it by clicking on Choose a backdrop. Click on Indoors in the list at the top. Then click on a theatre backdrop. 7) Bea Bac Beom Click and crag the drum to the bottom of the Stage. nipsifprojectsraspberrypiorgleniprojectsrock bandiprint 5s 4187126, 11.08 aM Rock band Your stage should now look similarto this: /npsufprojectsraspberrypiorgleniprojectsrock bandiprint ens 4187126, 11.08 aM Rock band Step 4 Making adrum Now youwill add code to your drum so that the drurn makes a sound when it's clicked, You can find the code blocks in the Scripts tab, and they are all colour-coded! First add the Music extension so you can play instruments. Click on the Add extension button in the bottom left-hand comer. —— ©. 2. Click on the drum sprite, and then drag these two blocks into the code area on the right: Ran aed FY Make sure that the blocks are connected together (like LEGO bricks). play drum (1) Snare Drum ~ for @ED beats Click on the drum to try out your new instrument! /npsufprojectsraspberrypiorgleniprojectsrock bandiprint 78 sires, 104004 Rockband Cr Challenge: improving your drum ‘Can you change the sound that the drum makes when it's clicked? Pees) Oe) Cae) enc (4) Crash Cymbal (5) Open Hi-Hat (6) Closed Hi-Hat Ubu (8) Hand Clap (9) Claves Can youalso get the drurn to make a sound when the space bar is pressed? You'll need to use this GXIMIIB block: EQ] when space ~ key pressed Ifyou want to copy your existing code, right-click on it and then click on duplicate. Duplicate ‘Add Comment Delete Block /npsufprojectsraspberrypiorgleniprojectsrock bandiprint ans 4187126, 11.08 aM Rock band Step5 Making asinger Now youwill add a singerto your band! Adda singer sprite to your Stage. e ‘Add a sprite from the Sprite Library Click on Choose a Sprite to open the Sprite Library: I You can search fora sprite, or browse forone by category. Click on a sprite to add it to your project: : oo ee ox4"r oma }* &# Moe nipsifprojectsraspberrypiorgleniprojectsrock bandiprint ons 4187126, 11.08 aM Rock band Before you can make your singer sing, you need to add a sound to your singer sprite. Make sure that you have selected your singer sprite, then click on the Sounds tab, and click on Choose a sound: Click on Voice in the list at the top, and then choose a sound to add to yoursprite. To use the sound, add the following code biocks to your singer spite: PCRS cee cc) Acme) Pet) Click on your singer on the stage and see what happens. Does she sing? nipsifprojectsraspberrypiorgleniprojectsrock bandiprint sons 4187126, 11.08 aM Rock band Step6 Costumes Now youwill make your singer look lke she’s singingl You can change how yoursinger sprite looks when it's clicked by creating a new costume. Click on the Costumes tab, and you'll see the singer costume, Right-click on the costume and then click on duplicate to create @ copy of it God | of Cosumes | qa Sin Glick on the new costume (called ‘Singer2’), and then select the line tool and draw lines so it looks like your singeris making a sound, PS i nipsifprojectsraspberrypiorgleniprojectsrock bandiprint 115 4187126, 11.08 aM Rock band ‘The names of the costumes aren't very helpful at the moment. Type into the text boxes of the costurnes to change theirnames to ‘not singing’ and ‘singing. a ... = = et ve aT mo Now that you have two different costumes for your singer, you can choose which costume isdisplayed! =| _- ‘Add these two code blacks to your singer sprit: Rn Ae Ces EU ee Ce MCU i DO Meee ae Tr Benes Ce MERI Ba The code biock for changing the costume isin the section, Click on your singer on the stage. Does she look like she is singing? Vv) Now make your drum look lke it’s being hit! v ‘+ Use the instructions for changing your singer sprite’s costume to help you. Remember to test that your new code works! nipsifprojectsraspberrypiorgleniprojectsrock bandiprint rans 4187126, 11.08 aM Rock band Challenge: improve your band Use what you've learnt in this project to make your own band! You can create any instruments you like — look at the available instrument sprites and sounds to get some ideas. 2SOOSDOOCO © © Mua You can use more sprites from the library, and you can also paint your own sprites! /npsufprojectsraspberrypiorgleniprojectsrock bandiprint 138 4187126, 11.08 aM Rock band © worvis my sprite jumping’ when t changes costume? When creating your own sprite, you may ‘This is because the two costumes aren't To fix this, make sure that the centres of find that when you click the sprite, it jumps’ as it changes costume. centered in the same place. your sprite's costumes are the same. Ifyou have a microphone, you can record your own sounds, and you can even use a webcam to hit your instruments! /npsufprojectsraspberrypiorgleniprojectsrock bandiprint cr rier} oT) Coen roll cymbal sans srt728, 11.08 aM Rock band Step7 What next? Now that you've built yourfrst Scratch project, why not take a look at the Lest in space (https://projects.raspberr ypi.org/en/projects/lost-in-space?utm_source=pathway&utm_medium=whatnext&utm_campaign=projec ts) Scratch project? Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commons license (https://creativecommons.org/licenses/by-sa/4.0/), View project & license on GitHub (https://github.com/RaspberryPiLearning/rock-band) hitpsiprojects.taspberypi.orglenprojectirock-bandiprint 155

You might also like