Game Development Reference
In-Depth Information
7
8 def update
9 change_direction if should_change_direction?
10 if substate_expired?
11 rand > 0.3 ? drive : wait
12 end
13 end
14
15 def change_direction
16 change = case rand ( 0. . 100 )
17 when 0. . 30
18 -45
19 when 30. . 60
20 45
21 when 60. . 70
22 90
23 when 80. . 90
24 -90
25 else
26 0
27 end
28 if change != 0
29
@object . physics . change_direction(
@object . direction + change)
30
31 end
32 @changed_direction_at = Gosu . milliseconds
33 @will_keep_direction_for = turn_time
34 end
35
36 def wait_time
37 rand ( 500. . 2000 )
38 end
39
40 def drive_time
41 rand ( 1000. . 5000 )
42 end
43
44 def turn_time
45 rand ( 2000. . 5000 )
46 end
47 end
The logic here:
Search WWH ::




Custom Search