Game Development Reference
In-Depth Information
30
31
def
turn_time
32
rand
(
300.
.
1000
)
33
end
34
end
TankNavigatingState
simply chooses a random free path, changes direction to it and
keeps driving.
13-advanced-ai/entities/components/ai/tank_stuck_state.rb
1
class
TankNavigatingState
<
TankMotionState
2
def
initialize
(object, vision)
3
@object
=
object
4
@vision
=
vision
5
end
6
7
def
update
8
change_direction
if
should_change_direction?
9
drive
10
end
11
12
def
change_direction
13
closest_free_path
=
@vision
.
closest_free_path
14
if
closest_free_path
15
@object
.
physics
.
change_direction(
Utils
.
angle_between(
16
@object
.
x,
@object
.
y,
*
closest_free_path))
17
18
end
19
@changed_direction_at
=
Gosu
.
milliseconds
20
@will_keep_direction_for
=
turn_time
21
end
22
23
def
wait_time
24
rand
(
10.
.
100
)
25
end
26
27
def
drive_time
28
rand
(
1000.
.
2000
)
29
end
30
31
def
turn_time
32
rand
(
300.
.
1000
)
33
end
34
end