I recently decided to have a go at making a ‘Guitar Hero’ clone in Scratch!
My first task was to make a guitar. Thankfully, there’s a great ‘Card Guitar’ tutorial on the MakeyMakey website:
Obviously my guitar looks nothing like the one in the tutorial — mine looks more like a banjo, and is made out of a used kitchen roll and an old mobile phone box! 🙂
My ‘banjo’ only has 4 buttons, but by encoding each note in binary it’s possible to play 15 different notes with these 4 buttons.
If you want to learn more about how the game was made, you can continue reading below!
The game works by adding up the values of the keys pressed to calculate the binary number total. For example, if the ‘z’ and ‘v’ keys are pressed then the note number is 8+1 = 9.
Here’s the code that calculates the note number:
As middle C in Scratch has a value of 60 (and not 1)…
…the game code just adds 59 to the binary note value to play the correct note:
This means that in the game, note 1 = c, note 2 = c#, note 3 = d, etc.
To play along to a song, the song also needs to be stored. This is done by using two lists, one for the notes to be played, and one for the times that the notes should be played.
In this example, note 1 (c) is played at 5 seconds, note 1 is played again at 5.5 seconds, note 3 (d) is played at 6 seconds, and so on.
The game creates a cloned sprite for each note, which switches to the correct costume, waits until just before it’s due to be played and then glides to the bottom of the screen:
Here’s a video of me (badly) playing ‘happy birthday’: