Game Development Reference
In-Depth Information
49
end
50
51
def
substate_expired?
52
now
=
Gosu
.
milliseconds
53
case
@sub_state
54
when
:waiting
55
true
if
now
-
@started_waiting
>
@will_wait_for
56
when
:driving
57
true
if
now
-
@started_driving
>
@will_drive_for
58
else
59
true
60
end
61
end
62
63
def
on_collision
(with)
64
change
=
case
rand
(
0.
.
100
)
65
when
0.
.
30
66
-90
67
when
30.
.
60
68
90
69
when
60.
.
70
70
135
71
when
80.
.
90
72
-135
73
else
74
180
75
end
76
@object
.
physics
.
change_direction(
@object
.
direction
+
change)
77
78
end
79
end
Nothing extraordinary here, and we need a concrete implementation to get a feeling how
it would work, therefore let's examine
TankRoamingState
. It will be the default state
which tank would be in if there were no enemies around.
Tank Roaming State
08-ai/entities/components/ai/tank_roaming_state.rb
1
class
TankRoamingState
<
TankMotionState
2
def
initialize
(object, vision)
3
super
4
@object
=
object
5
@vision
=
vision
6
end