Game Development Reference
In-Depth Information
Vigilante Tank FSM
If you are on a path to become a game developer, FSM should not stand for
Flying
Spaghetti Monster
for you anymore.
Implementing AI Vision
To make opponents realistic, we have to give them senses. Let's create a class for that:
08-ai/entities/components/ai/vision.rb
1
class
AiVision
2
CACHE_TIMEOUT
= 500
attr_reader
:in_sight
3
4
5
def
initialize
(viewer, object_pool, distance)
6
@viewer
=
viewer
7
@object_pool
=
object_pool
8
@distance
=
distance
9
end
10
11
def
update
12
@in_sight
=
@object_pool
.
nearby(
@viewer
,
@distance
)
13
end
14
15
def
closest_tank
16
now
=
Gosu
.
milliseconds
17
@closest_tank
=
nil
18
if
now
-
(
@cache_updated_at
||= 0
)
>
CACHE_TIMEOUT