Class: TankNavigatingState
Instance Method Summary
collapse
#drive, #enter, #on_collision, #should_change_direction?, #substate_expired?, #wait, #waiting?
Constructor Details
Returns a new instance of TankNavigatingState.
2
3
4
5
|
# File 'lib/entities/components/ai/tank_navigating_state.rb', line 2
def initialize(object, vision)
@object = object
@vision = vision
end
|
Instance Method Details
#change_direction ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/entities/components/ai/tank_navigating_state.rb', line 12
def change_direction
closest_free_path = @vision.closest_free_path
if closest_free_path
@object.physics.change_direction(
Utils.angle_between(
@object.x, @object.y, *closest_free_path))
end
@changed_direction_at = Gosu.milliseconds
@will_keep_direction_for = turn_time
end
|
#drive_time ⇒ Object
27
28
29
|
# File 'lib/entities/components/ai/tank_navigating_state.rb', line 27
def drive_time
rand(1000..2000)
end
|
#turn_time ⇒ Object
31
32
33
|
# File 'lib/entities/components/ai/tank_navigating_state.rb', line 31
def turn_time
rand(300..1000)
end
|
#update ⇒ Object
7
8
9
10
|
# File 'lib/entities/components/ai/tank_navigating_state.rb', line 7
def update
change_direction if should_change_direction?
drive
end
|
#wait_time ⇒ Object
23
24
25
|
# File 'lib/entities/components/ai/tank_navigating_state.rb', line 23
def wait_time
rand(10..100)
end
|