Dan Waters takes you on a journey of building his GuitarrMatey game with XNA Game Studio, guiding you through the history of how he designed the game, plus step by step instruction on creating the game, including how to use the Softimage XSI|Mod Tool to design your own 3D models.
1. Introduction
Years ago, as a budding programmer and avid gamer, I developed an interest in creating a game of my own. At the time, I had a few options, including DirectX 6 and OpenGL. With no available tools for developing 3D models, coupled with a lack of understanding of 3D in general, my early attempts at creating a game just didn’t go as I wanted. I was able to understand and implement the basics – for example, spinning, colored cubes – but that didn’t impress me very much. Reluctantly, my game development ambitions were pushed aside. In 2007, I began playing with XNA Game Studio Express, and had a working 2D game in less than ten hours! This was a major accomplishment for me, and I yearned to move into the 3D world.
In early 2008, I learned about a free modeling tool from Avid called SOFTIMAGE|XSI Mod Tool. This stripped-down version of XSI allowed me to create simple models for use in an XNA Game Studio game. Building on my understanding of XNA Game Studio and the C# programming language, I decided to rekindle my 3D game ambitions. This moment in time marks the birth of the popular GuitarrMatey video tutorial series.
GuitarrMatey
I originally began building a really cool guitar model in XSI that I was going to somehow work into a game. As time went on, I learned more about DirectX shaders and animation using bones. I felt like I was ready to build a simple proof-of-concept game.
GuitarrMatey is certainly more of a proof-of-concept than a proper game. It has many of the things a “real” game has, such as dynamic audio, character animation, game states, and complex controller input. Aside from that, it’s not exactly a paramount example of good game design. As I was brainstorming ideas for the tutorial series, I made a list of things that I thought would maximize the coolness factor. I decided that guitars and pirates, two of the coolest things imaginable, should be together in a game. The result is a game that allows to you to improvise notes of a scale as pirates animate in time with your playing. Get introduced to the game with Video 1: Introduction.
2. Starting from scratch – where do I begin?
The process shown in the tutorials is slightly different than what I actually went through to develop the game, and the reason for this is simple: I made a lot of mistakes and I don’t want you to make the same ones. Depending on how you work, different approaches might work better for you. Personally, I wanted to have a few assets available so that I could see tangible results when I began working on the code. This meant that I would need some simple models and perhaps a texture or two. Before creating models in XSI Mod Tool, it’s very important to understand how Mod Tool and XNA Game Studio work together. This integration is described in great detail in Video 2: XSI and XNA Projects. Once all of the file paths and projects are set up and ready to work together, the workflow between the two tools becomes very seamless and easy to manage.
3. Building a Simple Model
After getting the projects set up, I began working on a model. Since Mod Tool is a completely new piece of software to me at this point, I ran through several of the Noesis tutorials that come with Mod Tool, viewable from the Netview window. I decided that the easiest model for me to build would be a pirate hat. I was slightly wrong, though, because a pirate hat is by no means an easy shape to recreate. I used Live Image Search to find some pirate hats and drew some basic sketches of a pirate hat. After a considerable amount of tinkering, I found that I could make a pirate hat in two basic shapes: a flat, folded cylinder for the brim, and a half-sphere for the bell of the hat. The modeling process is detailed in Video 3: Making a Really Simple Model. Before texturing the model, I wanted to ensure that the bare model worked in my XNA Game Studio game. I exported the model to .FBX format so that I could use a standard content importer, and began working on the code to display it.
4. Displaying a Simple Model in XNA Game Studio
The reason I chose to use .FBX format instead of the proprietary .XSI format for this basic example is that there are lots of examples on the web explaining how to display .FBX models, and there is less configuration required in your code to get it working. The process is detailed in Video 4: Displaying a Simple Model in XNA. The Draw method in this example is nearly identical to the samples you’ll see in any introductory article, or in the MSDN article explaining how to display a 3D model. This is mostly done for consistency and to get the viewer acquainted with the process.
5. Texturing
Texturing is a process that takes a decent amount of spatial intellect to understand. Most of it is coming to terms with what UV coordinates are, as well as the texturing tools available in Mod Tool. The texturing process is detailed in Video 5: Texturing for XNA using Mod Tool. One thing I found useful was to understand that you should have only one texture projection for any set of polygons. Removing extraneous texture projections, which can be created by many common operations in Mod Tool, can solve a lot of texture-related problems. This video also briefly explains materials in Mod Tool, and highlights the fact that Mental Ray shaders are not supported in XNA Game Studio. Thusly, it’s important to use either your own DirectX shaders or the ones supplied with Mod Tool.
After this video, I begin working more extensively with the .XSI file format when I export and publish to the XNA Game Studio project. Eventually, using Mod Tool’s native .XSI format becomes necessary in the project to utilize the animation API included with the Mod Tool package.
6. Rigging, Weight Painting, and Animating for XNA Game Studio Using XSI
There are three sub-videos in this section that deal with a process normally left to the professional 3D folks. Rigging refers to the application of a skeletal system (bones, joints) to a polygon mesh. Weight Painting helps you fine-tune the influence that a given bone has over different vertices in the mesh (for example, improper weight painting can cause your character’s head to deform when moving the knee, etc.). Animation refers to the manipulation of translation, rotation, and scale parameters over time. For a jumping animation, there is translation involved (moving upward and down again) as well as rotation of bones (to imply rotation of bones around joints in the skeleton). Of all the different topics covered in this series, this is the most important to understand and was the most grueling to produce because I had no experience doing these things in 3D tools. The making of the jumping pirate is detailed in this series of three videos: Rigging, Weight Painting, and Animating. This video marks the start of .XSI file format usage, because animations are baked directly into the .XSI file and the publication to your game is very straightforward.
7. Creating the Game
After creating this more complex model with animations, I tweaked the code in the game considerably to make use of the API provided by Avid for displaying .XSI models in XNA Game Studio. A custom content importer and processor is used (Crosswalk) and there is animation code that is specific to XSI models. A major benefit of using this code is that most of the boilerplate animation routines are canned inside Avid’s API for you, so you can begin working with your animated model right away.
In this video, you’ll also see how to gather some basic controller input and fire the animations.
This video in particular is very long, because it details a nearly complete overhaul of the game line-by-line to support skinned 3D models and animations. Video 7: Creating the Game
8. Creating Music and Sound
I used a pretty standard backing track that I improvised. This video is unique in that it shows the audio production side of things. It’s also the video in which I start thinking about how real guitar chords will be represented in the game and mapped to the guitar controller. The patterns shown and developed for chords in the game are logical, but mostly arbitrary. The backing track recorded in the beginning of the video is in the key of E minor, leading to a solo scale in E minor pentatonic (five notes in the scale). If you’re not a music geek, this should still make sense. Video 8: Creating Music and Sound
There are several different possible sounds that you can create in the game. Every single one of those notes and chords was meticulously recorded with a real guitar!
9. Audio in XNA Game Studio Using XACT
XACT is an incredibly powerful tool from the DirectX SDK. It also comes with XNA Game Studio. While it takes some getting used to, it can be utilized to create dynamic 3D sound. I used it in its most basic form; I created an index of sounds that can be played ad-hoc at any time. In Video 9: Audio in XNA using XACT, you’ll see how to create a basic audio package using the tool and create a simple audio engine in XNA Game Studio to play those sounds.
10. Determining What’s on the Guitar Controller
At this point, I had all my audio and graphical assets at my disposal, so it was time to begin thinking about input. It occurred to me that I had no idea what the buttons on the guitar meant (for example, what is the “whammy bar?” Where’s the Orange button on my controller?). It turns out that the guitar controller can be used exactly like a normal Xbox 360 Controller; each of the controls maps to a button or thumbstick on a standard controller. In Video 10: Determining What’s on the Guitar Controller, I wrote a small test application to determine what input I was getting. I later used that knowledge in my input routine.
11. Handling Complex Input & Final Code Walkthrough
Once I had my input mapped, I added some finishing touches to the game as well as implementing the method that gets input from the guitar controller. One big problem that I had to solve reared its ugly head. I had a long list of possible chords or single notes that could be played. How could I tell what grouping of notes was being held down when the player activated the strum bar? The player can be holding down zero, one, or many different keys when he or she strums the guitar, and that had to be translated in an intelligent way. I built a fairly complicated infrastructure to support this. In the code, you’ll see a lot of references to GuitarNote and other esoteric classes. In one place, you’ll even see a lot of code that looks like binary. This was just my special way of solving this problem, and it worked just fine. The final code walkthrough is detailed in Video 11: Handling Complex Input & Final Code Walkthrough.
To look at it from the perspective of the update method, when you get controller input, there needs to be a unique way to identify the state of the fret board. I was going to use something similar to bit flags in C or C++. For example, if you are holding down the green key and nothing else, I wanted to have a value representing that state that looked like 10000 (or “ON, off, off, off, off” where the Green key is on). Since you can’t represent binary numbers in C#, I just used plain old decimal. The above number is literally ten-thousand.
In the code, this is actually a six-digit number. The first digit is 0 or 1 and represents a modifier. If the modifier is 1, then single notes are played on a higher scale.
Ignoring the modifier bit, you’ll see that any combination of the five guitar keys can be represented by a five-digit number. The way I construct this number at run time is relatively simple. I have a value starting at zero. If the green button is down, I set the leftmost “bit” to 1 by adding 10000 to the base value. If the red button is down, I add 01000. If the yellow button is down, I add 00100, and so forth. After this number is generated, I use a simple lookup table to map it to an enumeration value. 11100 maps to GuitarNote.EMajor, for example. Then, in the audio engine, this enumeration value is mapped to the name of a sound cue, and the sound cue is played using a simple method call like Audio.PlayGuitarNote(GuitarNote note).
The code in this video shows a lot of creative thinking that went into the resolution of a simple gameplay issue. It really represents the inherent fun aspect of game development – creative problem solving.
The video also gives you a full walkthrough of the entire game in its completed state, so that anything that may have been skipped over is addressed.
12. Deployment
The series concludes with a how-to video describing the deployment process to Xbox 360. Video 12: Deploying to the Xbox 360. Personally, this was much easier than I had expected. It was nice to see that since I had developed on the PC using a USB guitar controller, I didn’t have to change any of my input routines. I literally deployed directly to the Xbox 360 console, with the only change being the XACT audio project build type.
Conclusion
Programmer art notwithstanding, GuitarrMatey is the product of my personal journey from “nothing” to “functional game” over the course of about a month. It shows that once you understand the basics, you can really get lost in the fun aspects of game development while letting XNA Game Studio do all the dirty work for you.
Regardless of your passion, there is something in game development for everyone. What was previously inaccessible or impossible to comprehend is now laid out nicely for you and supported by the incredibly solid XNA Game Studio platform. The game development world is now your oyster. Enjoy!