Building XNA 2.0 Games- P7: I would like to acknowledge John Sedlak, who saved this book from certain doom, as well asall of the great guys in the XNA community and Microsoft XNA team, who helped me with allof my stupid programming questions. (That is actually the term used—“stupid programmingquestion”—and it is a question that one should not have to ask if one has been approached towrite a book about the subject.)
Nội dung trích xuất từ tài liệu:
Building XNA 2.0 Games- P7 CHAPTER 6 ■ BRINGING IT TO THE GAME 167Putting Scripting into PracticeLet’s look at how this scripting language actually works in a situation we could be using forZombie Smashers XNA. We’ve mapped out all of the important keyframes in the animation second (for secondaryattack) and connected them with gotos in Figure 6-9. We’ve left out frame numbers, opting touse some attractive lines instead.Figure 6-9. Gotos in “second” It’s all one animation, but it’s split into two rows that just happen to coincide with theregular shoot and shoot up animations. At the start of the animation, we’ll check whether Up was pressed. If it was, we’ll jump tothe start of the shoot up segment. At the ends of both the regular shoot and shoot up anima-tions, we’ll check for input to send us to the start of the shooting animations. If we don’t getinput, we’ll move to the end of the animation and finally idle. Let’s look at a more complicated example for the animation attack, shown in the samepseudo-format in Figure 6-10. Now we’re getting into the good stuff! We have got a four-hit combo: spanner-whack,spanner-whack, spanner-whack, flying kick. The player just needs to keep mashing thosebuttons. Of course, if the player doesn’t keep mashing the buttons, each individual attack hasa few back-to-idle frames, so we have a totally legit combo now. The fun part is at the end. If the player does an uppercut (Down on the left analog + Y),we’ll jump to the last row, launching skyward with a nice spanner-uppercut and finishing up inthe fly animation. See how powerful this stuff is? We can really go nuts with these combos—air juggles, complexground combos, far-reaching mega slams. We’ve just opened up a really fun and exciting partof this whole design racket!168 CHAPTER 6 ■ BRINGING IT TO THE GAME Figure 6-10. Complex stuff: the “attack” animation Odds and Ends: Cleanup Now that we have our script system in place (and gotten all hot and bothered in the process), we can clean up some placeholder animation code in Character—namely jumping and landing. Our character does look a little stiff-legged on the landing, doesn’t he? In Update(), we’re going to change the key input part to this: #region Key input if (animName == idle || animName == run) { if (keyLeft) . . . if (keyAttack) { SetAnim(attack); } if (keySecondary) { SetAnim(second); } CHAPTER 6 ■ BRINGING IT TO THE GAME 169 if (keyJump) { SetAnim(jump); }} And then we’ll update Land() to look like this:private void Land(){ State = CharState.Grounded; SetAnim(land);} This means that in our character definition file (guy.zmx), we need to create a jump anima-tion, which will have our guy crouching and end in a joymove, setjump 600, and setanim fly,and a land animation, which will end in a setanim idle. We’ve basically added an extra anima-tion between idle/running and flying through the air. These animations are then responsiblefor progressing the character’s motion.ConclusionWe’ve made some terrific headway into our game. We created our game solution, moved in allof the right classes, loaded our content, loaded our data, and set up what is shaping up to be avery complicated, very expressive Character class, complete with simple movement and colli-sion detection. Next, we mapped out our scripting language, modified our character editor to allow scriptediting, and implemented script parsing and running from our Character class. We looked athow we can use our ultra-simple scripting language to add a lot of depth and expressiveness toour characters. We’ll be building on this quite a bit as we flesh out our game. Our next order of business is going to involve lots of particles: sparks, muzzle flashes,explosions, and more. We’ll call it particle mayhem!CHAPTER 7■■■Particle MayhemBring Out the Smashing!D esigning particle systems is probably one of the most exciting aspects of independent gamedevelopment, yet it also happens to be an area where a lot of aspiring indie developers fall flat.This is another programmer art issue. While large teams with big budgets can rely on tools tobetter facilitate art direction for particle systems, independent developers must either work theentire thing out for themselves or try to collaborate with an artist to really nail the feel of it.Furthermore, many developers often take a side road and never come back once they hit parti-cles. After building a basic system, it’s easy to get caught up in adding features to the particlesystem and ...