Game Development Reference
In-Depth Information
This way, the AIController 's Update function can simply call the current
state's Update :
Click here to view code image
function AIController .Update( float deltaTime )
state .Update( deltaTime )
end
With the design pattern implementation, the SetState function is also much
cleaner:
Click here to view code image
function AIController .SetState( AIState newState )
state .Exit()
state = newState
state .Enter()
end
With the state design pattern, all state-specific behavior is moved into the sub-
classes of AIState . This makes the AIController code much cleaner than in
the previous implementation. The State design pattern also makes the system far
more modular. For instance, if we wanted to use the Patrol code in multiple state
machines, it could be dropped in relatively easily. And even if we needed slightly
different Patrol behavior, the Patrol state could be subclassed.
Strategy and Planning
Certain types of games require AI that is more complex than state-based enemies.
In genres such as real-time strategy (RTS), the AI is expected to behave in a man-
ner similar to a human player. The AI needs to have an overarching vision of what
it wants to do, and then be able to act on that vision. This is where strategy and
planning come into play. In this section, we will take a high-level look at strategy
and planning through the lens of the RTS genre, though the techniques described
could apply to other genres as well.
Search WWH ::




Custom Search