Game Development Reference
In-Depth Information
The mouse is handled separately from the keyboard (in UpdateMouse ), but with
the same idea. A mouse click is first sent to the UI (to see if a button was clicked),
and then if the UI does not care about the click, it's sent to the GameState . The
GameState checks the mouse clicks to select the appropriate Tile when one
is clicked. Because it's also possible to pan with the mouse (instead of using the
keyboard), UpdateMouse also does some checks to see if the mouse is on the
edge of the screen, which signifies a pan must occur.
Physics
Physics is only really used in this game for the purpose of collision detection.
Due to this, all the PhysicsManager does is generate a model space bounding
sphere or bounding box for a particular model. Because the model space bounding
data will never change for the same model, it caches it in a sorted list. So every
time a particular mesh (such as “Miner”) is requested, it checks to see if it already
previously computed the bounding sphere or box. This way, every time an enemy
spawns, there's no need to recalculate the model space bounds.
In terms of actual collision detection, it's really only used to check the picking
ray against all of the tiles in the world. XNA provides built-in Ray , Boundin-
gSphere , and BoundingBox (AABB) classes. All of these classes can check
for intersections with each other, so I did not have to implement any of the inter-
section tests that were covered in Chapter 7 . The intersection between the picking
ray and the tiles occurs in the Level.Intersects function. This function ba-
sically creates a list of all the tiles that intersect with the ray and then selects the
tile that's closest to the start position of the ray.
Localization
As mentioned in Chapter 10 , User Interfaces , ” it's typically not a good idea to
hard-code text strings that are displayed onscreen because it makes it more com-
plex to translate the game to other languages. For this game, all text strings that
are displayed onscreen (other than the debug FPS) are stored in the Languages/
en_us.xml file. If you open up the file, you'll see the format is relatively simple,
with the data for each entry stored inside <text> tags, like this:
Click here to view code image
<text id='ui_err_money'>You don't have enough
money.</text>
Search WWH ::




Custom Search