Game Development Reference
In-Depth Information
back to the start goal, which isn't what the enemies need. So to eliminate the need
to reverse the path, it's instead computed backward.
Camera and Projection
The game uses an orthographic projection, which was covered in
Chapter 4
. This
meansthatthereisnosenseofdepthbecauseobjectsfurtherawayfromthecamera
are not smaller. As for the camera (in Camera.cs), it's fairly simple in this game.
There really is not much functionality beyond the ability to pan the camera around
the level. In order to pan, both the eye position and the target position of the cam-
era are changed by the same amount, which is passed to the camera via the
Ad-
dToPan
function. The camera can also zoom in and out if the mouse scroll wheel
is used. Finally, there's also some code for animating the camera to a specific loc-
ation, though it's currently not in use.
enable the player to click and select a tile. Even though picking is a camera-related
algorithm, the code for this is in
InputManager.CalculateMouseRay
. In
order to perform picking, you need to know both the position of the mouse in
screen space as well as the camera matrix. So the choice was to either pass in the
position of the mouse to the camera or have the input manager access the cam-
era matrix. Because the drawing code also needs the camera matrix, and the cam-
era matrix was already globally accessible through
GameState
, the picking code
ended up in
InputManager
.
Input
Everything related to the keyboard and mouse input is in InputManager.cs. The
keyboard binding system is very similar to the “more complex system” discussed
tion such as
Pan_Left
is bound to a specific key and a specific state of that key
(either just pressed, just released, or held).
Then every frame, the
UpdateKeyboard
function is called, which makes a
linked list of all the actions that are active on that particular frame. This list is
first passed to the UI, which can process any actions it cares about. The remaining
actions are then sent to
GameState
for processing. Right now, the only actions
GameState
processes are the bindings related to panning because it has access
to the
Camera
class.