Game Development Reference
In-Depth Information
Both towers use functions that iterate through all the enemies in the world. In
the case of the ProjectileTower , it finds the closest enemy, whereas the
SlowTower findsalltheenemieswithinrange.Bothofthesefunctionsusebrute-
force algorithms to determine which enemies to affect. One way to solve this issue
would be through the use of a partitioning algorithm such as a quadtree, which
was mentioned in Chapter 7 . But implementing such an algorithm is beyond the
scope of this topic, so for simplicity the code here sticks to the brute-force system.
However, if __Defense were to be a commercial game, we likely would want to
eliminate the brute-force algorithm for performance reasons.
The Enemy game object has some custom behavior that allows it to move along
a given path through the world. It has access to a linked list of nodes representing
the path that's generated by the Pathfinder . In the Update function, it uses
linear interpolation to move between two nodes; once it reaches a node, it then
continues to the next node on the path. The facing of the enemy is computed using
quaternions in the SetDirection function, and a couple of assorted functions
allow for enemies being snared (as in Figure 14.2 ) or killed.
Figure 14.2 Enemies in blue are snared.
Search WWH ::




Custom Search