Class: TankFightingState
Instance Method Summary
collapse
#drive, #enter, #on_collision, #should_change_direction?, #substate_expired?, #wait, #waiting?
Constructor Details
Returns a new instance of TankFightingState.
2
3
4
5
6
|
# File 'lib/entities/components/ai/tank_fighting_state.rb', line 2
def initialize(object, vision)
super
@object = object
@vision = vision
end
|
Instance Method Details
#change_direction ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/entities/components/ai/tank_fighting_state.rb', line 15
def change_direction
change = case rand(0..100)
when 0..20
-45
when 20..40
45
when 40..60
90
when 60..80
-90
when 80..90
135
when 90..100
-135
end
@object.physics.change_direction(
@object.direction + change)
@changed_direction_at = Gosu.milliseconds
@will_keep_direction_for = turn_time
end
|
#drive_time ⇒ Object
40
41
42
|
# File 'lib/entities/components/ai/tank_fighting_state.rb', line 40
def drive_time
rand(5000..10000)
end
|
#turn_time ⇒ Object
44
45
46
|
# File 'lib/entities/components/ai/tank_fighting_state.rb', line 44
def turn_time
rand(300..3000)
end
|
#update ⇒ Object
8
9
10
11
12
13
|
# File 'lib/entities/components/ai/tank_fighting_state.rb', line 8
def update
change_direction if should_change_direction?
if substate_expired?
rand > 0.1 ? drive : wait
end
end
|
#wait_time ⇒ Object
36
37
38
|
# File 'lib/entities/components/ai/tank_fighting_state.rb', line 36
def wait_time
rand(50..300)
end
|