class TankMotionState

Public Class Methods

new(object, vision) click to toggle source
# File lib/entities/components/ai/tank_motion_state.rb, line 2
def initialize(object, vision)
  @object = object
  @vision = vision
end

Public Instance Methods

change_direction() click to toggle source
# File lib/entities/components/ai/tank_motion_state.rb, line 11
def change_direction
  # Override
end
drive() click to toggle source
# 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() click to toggle source
# File lib/entities/components/ai/tank_motion_state.rb, line 19
def drive_time
  # Override and return a number
end
enter() click to toggle source
# File lib/entities/components/ai/tank_motion_state.rb, line 7
def enter
  # Override if necessary
end
on_collision(with) click to toggle source
# 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?() click to toggle source
# 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?() click to toggle source
# 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() click to toggle source
# File lib/entities/components/ai/tank_motion_state.rb, line 23
def turn_time
  # Override and return a number
end
update() click to toggle source
# File lib/entities/components/ai/tank_motion_state.rb, line 27
def update
  # Override
end
wait() click to toggle source
# 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() click to toggle source
# File lib/entities/components/ai/tank_motion_state.rb, line 15
def wait_time
  # Override and return a number
end
waiting?() click to toggle source
# File lib/entities/components/ai/tank_motion_state.rb, line 38
def waiting?
  @sub_state == :waiting
end