Game Development Reference
In-Depth Information
Game Objects
The base game object class is in Objects/GameObject.cs. In __Defense , all game
objects are both drawable and updatable, so there isn't a complex hierarchy of in-
terfaces to implement for different categories of game objects. The world trans-
form matrix is built from a vector for position, a float for scale, and a quaternion
for the rotation, as discussed in Chapter 4 , “ 3D Graphics .” All game objects have
a bounding sphere, and any game objects that also want to have an AABB (such
as the Tiles) can set the m_bUseAABB Boolean to true in their constructor.
The Tower class (Objects/Tower.cs) inherits from GameObject and has all the
behaviorspecifictotowers.Mostnotably,ithasfunctionsforbuildingandupgrad-
ing towers, as well as changing the texture depending on whether or not the tower
is active. Because the game currently has two types of towers, it makes sense that
there are two children of Tower : ProjectileTower and SlowTower . The
custom behavior for each of these towers is more or less implemented in its Up-
date functions.
The Tile class that inherits from GameObject really doesn't have much func-
tionality—it just provides for being able to attach a Tower onto a Tile . It may
seem like overkill to have the Tile as a separate game object, but this was done
so that the height of the tiles can dynamically change. This still would have been
possible even if the tiles weren't game objects, but it definitely was a simpler im-
plementation to make them a subclass of GameObject . The children class of
Tile ( TileRed and TileGreen ) were intended to have different functionality
than the base Tile , but they don't really anymore (except red tiles can't be built
on).
Projectile s are spawned by ProjectileTower , and all they do is travel
toward the enemies and deal damage when they get to them. The movement is
done with a lerp (discussed in Chapter 3 , “ Linear Algebra for Games ”), and they
just slowly get closer and closer to the enemy's position. Originally, the collision
between the projectile and the enemy was done using an instantaneous bounding
sphere check (like in Chapter 7 , Physics ). But the problem with this was that the
higher level enemies had such huge bounding spheres that the projectile would al-
most instantly collide and disappear. So to make the game more challenging, the
code was changed so that irrespective of the enemy size, the projectile has to make
it to the center of the enemy to deal damage.
Search WWH ::




Custom Search