Make a Guitar Hero-style rhythm action game | Wireframe #62

Channel your inner rock god with our plucky homage. Mark Vanstone has the code in this month’s edition of Wireframe magazine, available now.

In 2005, a new game let players live out their rock star fantasies. Having already made specialised game controllers for Konami, American firm RedOctane enlisted the help of Harmonix to help them create Guitar Hero: a game where the aim was to play along with a music track by hitting the right buttons on a guitar-shaped controller. The game was an instant hit, spawning over 20 sequels and spin-offs over the course of around five years.

The original Guitar Hero on the PS2. Rock, rock, rock.
Guitar Hero, while hugely popular on the PS2, also had versions on numerous other consoles and computers.

The guitar controller featured five coloured buttons representing different notes, a strumming bar that had to be hit in time with the notes being played, and a whammy bar to change the pitch of the notes. The buttons corresponded with a scrolling display of coloured circles that moved down the screen as the music played. If the player ‘strummed’ the guitar at the correct time while holding down the correct coloured button, they scored points and kept the (virtual) audience entertained.

For our Pygame Zero version, we don’t have access to a custom-designed controller, so we’ll have to use a standard computer keyboard. We can set up the letters Z, X, C, V, and B as the five buttons. Then we’ll use the SPACE bar to strum the notes as they arrive at the bottom of the fretboard. We can make a list of Actors for the coloured circles which we’ll then move down the screen every time update() is called. We have five strings numbered 0 to 4 to attach our coloured circles to, and these need to be organised so they hit the bottom target points exactly when the note plays.

Our rocking Pygame Zero homage to Guitar Hero.
Our rocking Pygame Zero homage to Guitar Hero.

We don’t want the coloured circles to get out of sync with the music, so the timing of the movement is key. We must make sure that the speed is consistent, regardless of the speed of computer or other things going on which may make the frame rate change. To do this, we need to work out the time between each frame, known as the delta time, and then move the coloured circles based on that value. If you’re using your own music for the backing track, you may need to play around with these values, but the way this sample is set up, the tuples in the counterPoints list are the string number and then the number of seconds at which the note should be played from the beginning of the song. This setup means the player can get ready to play the note as it comes down the fretboard, press the appropriate button just before it gets to the bottom target, and if they press the SPACE bar as the coloured circle goes over the target, we fire off a ‘shine’ animation to indicate they’ve scored points. We can give them a little leeway so that they don’t have to be too precise with the SPACE bar press.

A lovely slab of code. Don't worry, though: no need to type it all in if you don't want to.
Here’s Mark’s code for a Guitar Hero-like rhythm action game. To get it running on your system, you’ll first need to install Pygame Zero. Full instructions can be found at wfmag.cc/pgzero. For the full code, head to our Github.

To make the music sample easy to play along with, I’ve edited a shortened version of one of my own fairly slow songs where the player plays the bassline. There are a couple of tricky bits in it, but you should be able to hit all the notes without too many attempts. You can use any MP3 or WAV file for this, just drop it in the music directory and change the line that reads music.play_once(‘themoment’). Then all you need to do is change the timings in the counterPoints list.

There are other things that you could add, like having error notes play if the wrong buttons are held down. There’s also that whammy bar on the original controller that may require a bit of lateral thinking to replicate on a keyboard, but we’ll leave that challenge to you.

Get your copy of Wireframe #62

You can read more features like this one in Wireframe issue 62, available directly from Raspberry Pi Press – we deliver worldwide.

We have a brand new subs offer! Subscribe to Wireframe for a year and get a FREE 8BitDo Pro 2 Bluetooth Controller worth £39.

The brand new edition of Wireframe, out now.

And if you prefer your magazines in digital form, you can also download Wireframe issue 62 as a free PDF!

2 comments
Jump to the comment form

Avatar

Is there a link to get 62 as a free download? I do not see any place to get it.

Reply to William Stottlemyer

Leave a Comment