tailieunhanh - Building XNA 2.0 Games- P6
Building XNA Games- P6: I would like to acknowledge John Sedlak, who saved this book from certain doom, as well as all of the great guys in the XNA community and Microsoft XNA team, who helped me with all of my stupid programming questions. (That is actually the term used—“stupid programming question”—and it is a question that one should not have to ask if one has been approached to write a book about the subject.) | CHAPTER 6 BRINGING IT TO THE GAME 137 Note In-line code is code that is kept in one place rather than componentized into methods and or classes. It is not a great idea in terms of organization but can be useful for optimizing memory usage. Updating the Animation We re basically copying and pasting the Update code from Gamel in CharacterEditor to Character with a few changes. We ll remove any functionality to determine whether the animation preview is playing. We ll also change some of the field names to make a bit more sense in the context. However the core logic remains unchanged update the frame index until we can t update it anymore and then loop back to the beginning. public void Update GameTime gameTime float et float region Update Animation Animation animation Anim KeyFrame keyFrame AnimFrame frame et if frame float frame - float AnimFrame if AnimFrame AnimFrame 0 keyFrame AnimFrame if 0 AnimFrame 0 endregion Updating the Location To update the location we ll simply add the trajectory multiplied by to the character s current location. If the character s state is STATE_GROUNDED and the character s x trajectory is not zero reduce the trajectory by . If the character is airborne the y trajectory s value will be increased by giving him a nice airborne arc. 138 CHAPTER 6 BRINGING IT TO THE GAME region Update Location By Trajectory Vector2 pLoc new Vector2 if State if Of - et if Of Of if Of et if Of Of et if State et et endregion Collision Detection Here comes a big chunk of code .
đang nạp các trang xem trước