Game Development Reference
In-Depth Information
developers are actively working on a content pipeline for MonoGame, so by the
time you're reading this, it may no longer be an issue. But for now, if you want to
change any of the models or textures for this game, you have to build the assets in
the XNA solution before it will work in the MonoGame ones.
Code Analysis
Compared to the sample game in the last chapter, there's a lot more code to go
through for __Defense . But that makes sense because the mechanics and interface
for this game are far more involved than Ship Attack . If you try to just jump in and
go through the files without reading this section, it may be difficult to grasp it all.
The best approach is to consult this section while perusing through the code.
Settings
Normally, it's best if settings are stored in external files for ease of editing (as in
Chapter 11 , “ Scripting Languages and Data Formats ). Because this game is relat-
ively simple, it felt a bit unnecessary to write the code for parsing in settings from
a file. However, I didn't want to just have all the parameters hard-coded all over
the place, so I ended up consolidating most of them into three source files.
Balance.cs has all of the parameters that affect the balance of the game. So para-
meters such as the number of waves, number of enemies, health of enemies, and
anything that adjusts the difficulty of the game are stored in Balance.cs. Any set-
tings that don't particularly affect the balance of the game (such as whether the
game is full screen and the camera speed) are in GlobalDefines.cs. Finally, De-
bugDefines.cs is mostly unused, but has a few parameters related to debugging the
game.
Singleton
A singleton is a class that's globally accessible and has only one instance in the
entire program. It's one of the most commonly used design patterns and often one
of the first classes to implement in a new engine. Although you could try to im-
plement a singleton using a global class, that's typically not the best way to do so.
For this game's code, the singleton implementation is in Patterns/Singleton.cs.
The way Singleton works is it's a templated class that has a static instance of
the templated type, and a static Get function that returns the static instance. It
sounds a little complicated, but the end result is that in order for a class to be a
singleton, all it must do is inherit from Singleton like this:
Search WWH ::




Custom Search