class AiInput

Constants

NAME_COLOR

Dark red

UPDATE_RATE

Attributes

name[R]
stats[R]

Public Class Methods

new(name, object_pool) click to toggle source
Calls superclass method Component::new
# File lib/entities/components/ai_input.rb, line 8
def initialize(name, object_pool)
  super(nil)
  @object_pool = object_pool
  @stats = Stats.new(name)
  @name = name
  @last_update = Gosu.milliseconds
end

Public Instance Methods

control(obj) click to toggle source
# File lib/entities/components/ai_input.rb, line 16
def control(obj)
  self.object = obj
  object.components << self
  @vision = AiVision.new(obj, @object_pool,
                         rand(700..1200))
  @gun = AiGun.new(obj, @vision)
  @motion = TankMotionFSM.new(obj, @vision, @gun)
end
draw(viewport) click to toggle source
# File lib/entities/components/ai_input.rb, line 46
def draw(viewport)
  @motion.draw(viewport)
  @gun.draw(viewport)
  @name_image ||= Gosu::Image.from_text(
    $window, @name, Gosu.default_font_name, 20)
  @name_image.draw(
    x - @name_image.width / 2 - 1,
    y + object.graphics.height / 2, 100,
    1, 1, Gosu::Color::WHITE)
  @name_image.draw(
    x - @name_image.width / 2,
    y + object.graphics.height / 2, 100,
    1, 1, NAME_COLOR)
end
on_collision(with) click to toggle source
# File lib/entities/components/ai_input.rb, line 25
def on_collision(with)
  return if object.health.dead?
  @motion.on_collision(with)
end
on_damage(amount) click to toggle source
# File lib/entities/components/ai_input.rb, line 30
def on_damage(amount)
  @motion.on_damage(amount)
  @stats.add_damage(amount)
end
update() click to toggle source
# File lib/entities/components/ai_input.rb, line 35
def update
  return respawn if object.health.dead?
  @gun.adjust_angle
  now = Gosu.milliseconds
  return if now - @last_update < UPDATE_RATE
  @last_update = now
  @vision.update
  @gun.update
  @motion.update
end

Private Instance Methods

respawn() click to toggle source
# File lib/entities/components/ai_input.rb, line 63
def respawn
  if object.health.should_respawn?
    object.health.restore
    object.move(*@object_pool.map.spawn_point)
    PlayerSounds.respawn(object, @object_pool.camera)
  end
end