Class: TankMotionState
- Inherits:
-
Object
show all
- Defined in:
- lib/entities/components/ai/tank_motion_state.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of TankMotionState.
2
3
4
5
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 2
def initialize(object, vision)
@object = object
@vision = vision
end
|
Instance Method Details
#change_direction ⇒ Object
11
12
13
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 11
def change_direction
end
|
#drive ⇒ Object
42
43
44
45
46
47
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 42
def drive
@sub_state = :driving
@started_driving = Gosu.milliseconds
@will_drive_for = drive_time
@object.throttle_down = true
end
|
#drive_time ⇒ Object
19
20
21
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 19
def drive_time
end
|
#enter ⇒ Object
7
8
9
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 7
def enter
end
|
#on_collision(with) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 68
def on_collision(with)
change = case rand(0..100)
when 0..30
-90
when 30..60
90
when 60..70
135
when 80..90
-135
else
180
end
@object.physics.change_direction(
@object.direction + change)
end
|
#should_change_direction? ⇒ Boolean
49
50
51
52
53
54
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 49
def should_change_direction?
return true unless @vision.can_go_forward?
return true unless @changed_direction_at
Gosu.milliseconds - @changed_direction_at >
@will_keep_direction_for
end
|
#substate_expired? ⇒ Boolean
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 56
def substate_expired?
now = Gosu.milliseconds
case @sub_state
when :waiting
true if now - @started_waiting > @will_wait_for
when :driving
true if now - @started_driving > @will_drive_for
else
true
end
end
|
#turn_time ⇒ Object
23
24
25
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 23
def turn_time
end
|
#update ⇒ Object
27
28
29
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 27
def update
end
|
#wait ⇒ Object
31
32
33
34
35
36
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 31
def wait
@sub_state = :waiting
@started_waiting = Gosu.milliseconds
@will_wait_for = wait_time
@object.throttle_down = false
end
|
#wait_time ⇒ Object
15
16
17
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 15
def wait_time
end
|
#waiting? ⇒ Boolean
38
39
40
|
# File 'lib/entities/components/ai/tank_motion_state.rb', line 38
def waiting?
@sub_state == :waiting
end
|