Class: TankFleeingState
Constant Summary
collapse
- MAX_FLEE_TIME =
15 * 1000
Instance Method Summary
collapse
#drive, #on_collision, #should_change_direction?, #substate_expired?, #wait, #wait_time, #waiting?
Constructor Details
#initialize(object, vision, gun) ⇒ TankFleeingState
Returns a new instance of TankFleeingState.
4
5
6
7
8
9
|
# File 'lib/entities/components/ai/tank_fleeing_state.rb', line 4
def initialize(object, vision, gun)
super(object, vision)
@object = object
@vision = vision
@gun = gun
end
|
Instance Method Details
#can_flee? ⇒ Boolean
11
12
13
14
|
# File 'lib/entities/components/ai/tank_fleeing_state.rb', line 11
def can_flee?
return true unless @started_fleeing
Gosu.milliseconds - @started_fleeing < MAX_FLEE_TIME
end
|
#change_direction ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/entities/components/ai/tank_fleeing_state.rb', line 25
def change_direction
closest_powerup = @vision.closest_powerup(
RepairPowerup, HealthPowerup)
if closest_powerup
angle = Utils.angle_between(
@object.x, @object.y,
closest_powerup.x, closest_powerup.y)
@object.physics.change_direction(
angle - angle % 45)
else
@object.physics.change_direction(
180 + @gun.desired_gun_angle -
@gun.desired_gun_angle % 45)
end
@changed_direction_at = Gosu.milliseconds
@will_keep_direction_for = turn_time
end
|
#drive_time ⇒ Object
43
44
45
|
# File 'lib/entities/components/ai/tank_fleeing_state.rb', line 43
def drive_time
10000
end
|
#enter ⇒ Object
16
17
18
|
# File 'lib/entities/components/ai/tank_fleeing_state.rb', line 16
def enter
@started_fleeing ||= Gosu.milliseconds
end
|
#turn_time ⇒ Object
47
48
49
|
# File 'lib/entities/components/ai/tank_fleeing_state.rb', line 47
def turn_time
rand(300..600)
end
|
#update ⇒ Object
20
21
22
23
|
# File 'lib/entities/components/ai/tank_fleeing_state.rb', line 20
def update
change_direction if should_change_direction?
drive
end
|