Class: TankStuckState
Instance Attribute Summary collapse
Instance Method Summary
collapse
#drive, #enter, #on_collision, #should_change_direction?, #substate_expired?, #wait, #waiting?
Constructor Details
#initialize(object, vision, gun) ⇒ TankStuckState
Returns a new instance of TankStuckState.
3
4
5
6
7
8
|
# File 'lib/entities/components/ai/tank_stuck_state.rb', line 3
def initialize(object, vision, gun)
super(object, vision)
@object = object
@vision = vision
@gun = gun
end
|
Instance Attribute Details
#stuck_at ⇒ Object
Returns the value of attribute stuck_at.
2
3
4
|
# File 'lib/entities/components/ai/tank_stuck_state.rb', line 2
def stuck_at
@stuck_at
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
|
# File 'lib/entities/components/ai/tank_stuck_state.rb', line 15
def change_direction
closest_free_path = @vision.closest_free_path_away_from(
@stuck_at)
if closest_free_path
@object.physics.change_direction(
Utils.angle_between(
@object.x, @object.y, *closest_free_path))
else
if @object.health.health > 50 && rand > 0.9
@object.shoot(*Utils.point_at_distance(
*@object.location,
@object.gun_angle,
150))
end
end
@changed_direction_at = Gosu.milliseconds
@will_keep_direction_for = turn_time
end
|
#drive_time ⇒ Object
38
39
40
|
# File 'lib/entities/components/ai/tank_stuck_state.rb', line 38
def drive_time
rand(1000..2000)
end
|
#turn_time ⇒ Object
42
43
44
|
# File 'lib/entities/components/ai/tank_stuck_state.rb', line 42
def turn_time
rand(1000..2000)
end
|
#update ⇒ Object
10
11
12
13
|
# File 'lib/entities/components/ai/tank_stuck_state.rb', line 10
def update
change_direction if should_change_direction?
drive
end
|
#wait_time ⇒ Object
34
35
36
|
# File 'lib/entities/components/ai/tank_stuck_state.rb', line 34
def wait_time
rand(10..100)
end
|