Game Development Reference
In-Depth Information
Microsoft sample (
http://xbox.create.msdn.com/en-US/education/catalog/sample/
work is beyond the scope of this topic, and it's not too important anyway because
it's just a graphical enhancement.
Sound
Because this game only has a handful of 2D sounds, the
SoundManager
class
is extraordinarily simple. All it does is load in WAV files into a dictionary, where
the key is the cue name, and the value is the wave file. Then sounds can be played
anywhere with the
PlaySoundCue
function:
SoundManager
.Get().PlaySoundCue("Alarm");
This isn't a fabulous implementation, however. Most notably, sounds will not
pause when the game is paused. Because of this, you would never want to actually
release a game with a sound system like the one here. But it works on a very basic
level.
User Interface
The UIsystem ended upbeing rather complex forthis game, most notably because
of the tooltips. But before we look at the tooltip code, let's look at the basic layout
of the UI system. There is a
UIScreen
class (in UI/UIScreen.cs) that represents
a particular menu or HUD. So, for example, the main menu is in
UIMainMenu
while the HUD that's shown during gameplay is in
UIGameplay
. The system
supports multiple
UIScreen
s visible at once, which is handled by the UI stack
in
GameState
. So, for example, the
UIGameplay
and
UIPauseMenu
screens
are both visible at the same time when the game is paused. Only the top-most
screen on the stack receives any input, however, which prevents actions such as
clicking on buttons in the build grid while the game is paused.
UIScreen
s can have any number of buttons (UI/Button.cs) on them. Every
frame, the active
UIScreen
receives the location of the mouse cursor and can
highlight a button as appropriate. If a click occurs, it will then call whatever func-
tion is registered to be called when that particular
Button
is clicked. Buttons can
be initialized in three different ways: They can be text-only buttons, image-only
buttons, or buttons that are “hot zones” (meaning they show tooltips, but can't be
clicked). For text-only and image-only buttons, the constructor requires specify-