Game Development Reference
In-Depth Information
27 when 90. . 100
28 -135
29 end
30 @object . physics . change_direction(
31 @object . direction + change)
32 @changed_direction_at = Gosu . milliseconds
33 @will_keep_direction_for = turn_time
34 end
35
36 def wait_time
37 rand ( 300. . 1000 )
38 end
39
40 def drive_time
41 rand ( 2000. . 5000 )
42 end
43
44 def turn_time
45 rand ( 500. . 2500 )
46 end
47 end
We will have much less waiting and much more driving and turning.
Tank Chasing State
If opponent is fleeing, we will want to set our direction towards the opponent and hit pedal
to the metal. No waiting here. AiGun#desired_gun_angle will point directly to our
enemy.
08-ai/entities/components/ai/tank_chasing_state.rb
1 class TankChasingState < TankMotionState
2 def initialize (object, vision, gun)
3 super (object, vision)
4 @object = object
5 @vision = vision
6 @gun = gun
7 end
8
9 def update
10 change_direction if should_change_direction?
11 drive
12 end
13
14 def change_direction
Search WWH ::




Custom Search