Sign in to follow this  
boehmz

How is Guitar Hero Programmed?

Recommended Posts

Do they just have a timer start with the song and tell it what notes need to be hit at certain time intervals(in a sense, brute force)? Is there any other way to do it than just have: when timer is between 3 and 3.5 seconds, give points if green button is strummed when timer is between 4 and 4.5 seconds, give points if yellow button is strummed when timer is between 5 and 5.5 seconds, give points if green button is strummed etc.

Share this post


Link to post
Share on other sites
Sounds like a good approach to me, except that 0.5 seconds per note is way too long.

Of course, it gets slightly more complicated when considering chords, held notes, hammer ons/pull offs and so forth...

Also, I guess tightly packed notes are handled, so that their "trigger time" can overlap.

Share this post


Link to post
Share on other sites
I believe that the engine works by comparing the current active input notes (fret or strummed, depending on GH version) to the notes nearby the current track time, where "nearby" is defined as being within a certain treshold distance from the note. This logic is executed when either the strum bar is moved (classic GH operation), or in case of the special fret buttons (lower on the neck on guitars > GH3), when the button is pressed. In essence, the core algorithm is just an one-dimensional position search with a distance treshold.

If nearby track notes that match the input notes are found, the game registers a success. Conversely, a failure is registered if track notes matching to the input notes are not found.

In case of the sliding notes, there is an additional logic to see whether the input buttons corresponding to the slides are held down during the duration of the track notes.

Hammer-ons and pull-offs work by observing the success status of the previously played consecutive notes.

Share this post


Link to post
Share on other sites
>>when timer is between 3 and 3.5 seconds, give points if green button is strummed
Ive never played the game so bare with me

if ( abs(time - eventtime)*(1.0/0.25) > 1 )
scoer = 0.0
else
score = 1.0

though there will be overlap between ( handled by a lerp)


sorry drunk as a fart ATM (sat night rah rah) but in case youre interested in created a 'fun' game, choose the middle of 'between 3 and 3.5 seconds' and deviate off that, i.e. never have a fixed value between X+Y is perfect + rest aint

Share this post


Link to post
Share on other sites
I can't tell you exactly how Guitar Hero is programmed as I have never seen the source, but I believe that they use a midi file for the notes, an mp3 (or equivalent) file for the actual songs, and the note positions are calculated based on the note delta times in the midi file.

Something like:


int NoteTime = (int)(((iNoteSpr.mRSNote.mStartTime + 0.0) / mSong.mTimeDiv) * (60000.0 / (mSong.mBPM)));
int NoteEndTime = (int)(((iNoteSpr.mRSNote.mEndTime + 0.0) / mSong.mTimeDiv) * (60000.0 / (mSong.mBPM)));


float len = (float)(240 / mNoteImages[0].mTex.Width);


float z = (float)(240.0 + (((songPos * 1000.0 - mNoteDelayTime - NoteTime) / (60000.0 / (mSong.mBPM))) / (60.0 / len)) * (240.0 * iNoteSpr.mRSNote.mDirVal));

if (iNoteSpr.mRSNote.mDirVal == -1)
z -= iNoteSpr.mTex.Width/2+mTarget.Width;


float w = Math.Abs((float)(240.0 + (((songPos * 1000.0 - mNoteDelayTime - NoteEndTime) / (60000.0 / (mSong.mBPM))) / (60.0 / len)) * (240.0 * iNoteSpr.mRSNote.mDirVal)) - z);



Which is from an abandoned game of mine... The code is a mess but it works..

The Frets on Fire source might be a good place to look (It is written in Python if I remember correctly).

Good luck.

Share this post


Link to post
Share on other sites
There are 5 buttons. These can be represented via an int, by setting bits.

Let track be made of adequate number of samples. At any given point in time, a certain set of buttons must be pressed.

int samples[];
notes = 0;
time = 0;
while (running) {
int buttons = readInput();
if (samples[time] != buttons) {
// wrong
} else {
// correct
}
time++;
Sleep(100);
}
This is probably the simplest possible solution, that just might work in practice.

An example:
// Yellow button is second
in binary: 000010
as integer: 2

Track requiring user to press yellow button from 0.5s to 1 second would be:
{0,0,0,0,0,2,2,2,2,2,2,0,0,0,.....}

Share this post


Link to post
Share on other sites
Yes, that may be true but Frets on Fire can import Guitar Hero songs, so at the very least the concepts are probably similar... At the end of the day it doesn't really matter how GH was programmed. If the OP wants to create a similar game than the Frets on Fire source is probably a good place to start (or at least better than trying to hard code every note).

Share this post


Link to post
Share on other sites
You open it the same way you open mp3 files. You get a music player that can read them. VLC plays them for instance. If you want to play them in software you should get a library for it. I have no idea what the most appropriate library for you would be, all I know is there's one here.

Share this post


Link to post
Share on other sites
Quote:
Original post by Holland
Quote:
Original post by Kwizatz
You can take a look at Frets On Fire's Source Code to get an idea.


This is assuming that FoF is programmed the same as GH, which it probably is not. I've played FoF and it doesn't seem as responsive or as fluid as GH.


A keyboard is not a game device, so to add to shadowisadog's post, you can't expect the same responsiveness from a keyboard that you get from a tailor made device for a game, specially because keyboards are evil.

Share this post


Link to post
Share on other sites
Check out this link on a tutorial to making a Guitar Hero type game using C#/XNA, I believe there are videos to watch on this how to program tutorial and maybe what you are looking for if you want to know exactly how it can be done.

http://blogs.msdn.com/dawate/archive/2008/02/05/building-a-3d-game-in-xna-from-scratch-free-video-tutorial-series-now-available.aspx

Share this post


Link to post
Share on other sites
While I don't know how Guitar Hero is implemented, I can tell you how we did it for our upcoming rythm game for PSN.

We basically use the same method you mentioned, only with millisecond precision.
The notes themselves are converted into our own format from MIDI files, so everything is sequenced in Acid using the actual soundtrack on a reference track. We then check on button presses weather or not the time of the press is within the given note. We use four buttons, and each has its own track in both the MIDI file and our own format. Accuracy is calculated by taking the start and stop times of the note and calculating a [0..1..0] interval for it, where 1 is a absolutely perfect hit, and 0 is a miss. We use thresholds to add some room before and after the actual MIDI note to accomplish this, along with normalized note lengths for regular notes. For hold notes (the ones where the player needs to hold a certain button down for the duration of the note) we add note duration so that the note actually consists of two separate though connected normalized notes. In this case, the player must press down within the first "virtual" note, and release on the second. The calculated [0..1..0] interval makes it very effortless to add several different accuracy points, such as "Bad", "Good", "Ok", "Miss", "Perfect" etc by simply defining a range for the accuracy point. A perfect hit for instance, is in the interval [0.90 - 1.0], while a "Good" hit is in the interval [0.78 - 0.90]. Note that the accuracy works on both "sides" of the absolute perfect (1.0), so in the example of the perfect hit given a note length of 100ms, it would actually be triggered if the current relative note time is between 90ms and 110ms.

Edit: Yikes, I messed up my numbers in the example there, and also failed to provide a more complete explanation. I guess that's what you posting in a hurry. The correct example of a perfect hit given a note length of 100ms, would be that the threshold value is added in a relative manner to the *start* of the note only, which is simply a millisecond value. So if the note start is 2050ms in the MIDI sequencer, the new note would start at 2000ms, and end at 2100 after the thresholds were applied. A perfect hit would then be between 40ms and 60ms in relative/local time, and between 2040ms and 2060ms in global time. In other words, we only use the start value for MIDI notes, and construct our own normalized notes using that value as the desired trigger point. Hold notes are as I said earlier slightly different, there we use both the start and the stop, where the start is the desired button press point, and stop the desired button release point. So what I said earlier about the buttons having their own track is only a semi-truth. They actually have two tracks each, one for hold notes and one for regular notes.

[Edited by - cmv on September 17, 2009 1:18:47 AM]

Share this post


Link to post
Share on other sites
I think that they have a tool where they play the song and add the notes. Then, in-game, everything is synced up (sound and notes stream). If a button is pressed when the corresponding note is due to be strummed, you've got a hit.

Share this post


Link to post
Share on other sites
If I had to guess (and remember this is a guess)...

They would have the song file which is your normal ogg/mp3 whatever. They have the event of when the song file starts and then simply use a data file that indicates "this note is played here" type of data. The notes would have a start time, end time, etc... and it would all be relative to the song's start time. Assign the note an ID and you have quick and easy network play, the game would transmit that note ID is hit or miss. With a bit of dead reckoning logic involved, network code would be super easy.

They can then adjust the data file's time frames by the options window's visual syncing/delay setting. Then for easy/medium/hard/expert levels they vary the threshold of "missing" a note. That's why when you play GH you see that the notes you are playing "look" like they follow the song but in actuality, they do not actually follow the song as the instrument would normally be played. This is because someone took a more aesthetic approach to creating the data track.

Anyway, that's just a guess.

Share this post


Link to post
Share on other sites
Thanks for responses guys! I will try to use a mix of these to see what works best. Just as a disclaimer, I'm not making a guitar hero clone. A friend asked me to help program a game that uses rhythm, however. It still requires buttons to be pressed to the beat of a song, but not quite as complicated as guitar hero. Thanks for the link to the guitar matey game, I will look at the source code to see if I can find any last bits of information before I start coding this weekend.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this