Game Development Reference
In-Depth Information
Visual debugging of AI behavior
Although it hurts the framerate a little, it is very useful when building not only AI, but the
rest of the game too. Using this visual debugging together with Demo mode, you can tweak
all the AI values to make it shoot more often, fight better, and be more agile. We won't go
through this minor tuning, but you can find the changes by
viewing changes introduced in
Making AI Collect Powerups
To even out the odds, we have to make AI seek powerups when they are required. The logic
behind it can be implemented using a couple of simple steps:
1. AI would know what powerups are currently needed. This may vary from state to
state, i.e. speed and fire rate powerups are nice to have when roaming, but not that
important when fleeing after taking heavy damage. And we don't want AI to waste
time and collect speed powerups when speed modifier is already maxed out.
2.
AiVision
would return closest visible powerup, filtered by acceptable powerup
types.
3.
Some
TankMotionState
implementation would adjust tank direction towards
closest visible powerup in
change_direction
method.
Finding Powerups In Sight
To implement changes in
AiVision
, we will introduce
closest_powerup
method. It
will query objects in sight and filter them out by their class and distance.
class
AiVision
# ...
POWERUP_CACHE_TIMEOUT
= 50
# ...
def
closest_powerup
(
*
suitable)
now
=
Gosu
.
milliseconds