Putting More Pieces TogetherThe title to this section is really accurate. Most programming, at least in some way, is like a jigsaw puzzle. It is about combining pieces in a manner that works best. Often times, you will obtain a completely different result just be re-ordering some of the steps. In this sense, programming is intellectually stimulating. There are so many millions of ways to accomplish any given task. Keep that in mind while reviewing the code I provide. It isn't written in blood any place that you have to do things a certain way -- at least, I don't think it is. The module, we are going to look at for the changes is the Menu module. The reason we are using this module is that it makes use of all of our new features, which makes it perfect for use as an example. You had better take a look at the code for the new module before we go any further. Now, I will help you locate all of the new stuff. To begin with, in Init_Menu() we load in the WAV file for the menu music and we set a new variable called "first_time" to TRUE. I hope the Load_WAV() call is self-explanatory. The new variable, on the other hand, is probably going to need a quick explanation. Basically, we need a way to find out when we are drawing one of the menus if we need to perform a transition or just draw it plain. Since we only want to transition once, upon entrance, we setup a variable to hold state information. Looking at the Process_Main_Menu() procedure we can see how to use the new routines. After the stuff has been drawn, and is ready to be displayed, we call Status_Sound() with our menu's music ID. The function returns the status of the sound and we AND it with DSBSTATUS_PLAYING to find out if our sound is currently playing. If it is not yet playing we make the call to play the sound and pass in DSBPLAY_LOOPING so that we don't have to keep calling Play_Sound(). It is important that we get the status on any sound that might be looping, since, by calling Play_Sound(), we reset its position to the beginning. It ends up sounding very interesting, and you know right away that you have botched it someplace. Once the sound is going we are ready to display our menu screen. If our first_time variable is still TRUE then we transition in, otherwise we just draw the screen normal. We also set the state to FALSE after we transition in so that we don't keep performing a transition. The variable also gets reset when certain menu items are selected. That is about all for the new stuff. I have scattered things around the Menu module, and there is some sound stuff in the Shapes module. I showed you how to implement the new things, which is extremely simple. If you can think of anything else to add feel free to do so. It is good practice.
|
|