class RTanque::Shell

Constants

RATIO
SHELL_SPEED_FACTOR

Attributes

arena[R]
bot[R]
fire_power[R]

Public Class Methods

new(bot, position, heading, fire_power) click to toggle source
# File lib/rtanque/shell.rb, line 12
def initialize(bot, position, heading, fire_power)
  @bot = bot
  @arena = bot.arena
  @fire_power = fire_power
  self.position = position
  self.heading = heading
  self.speed = self.class.speed(fire_power) # TODO: add bot's relative speed in this heading
  @dead = false
end
speed(fire_power) click to toggle source
# File lib/rtanque/shell.rb, line 8
def self.speed fire_power
  fire_power * SHELL_SPEED_FACTOR
end

Public Instance Methods

bound_to_arena() click to toggle source
# File lib/rtanque/shell.rb, line 22
def bound_to_arena
  false
end
dead!() click to toggle source
# File lib/rtanque/shell.rb, line 30
def dead!
  @dead = true
end
dead?() click to toggle source
# File lib/rtanque/shell.rb, line 26
def dead?
  @dead ||= self.position.outside_arena?
end
hits(bots, &on_hit) click to toggle source
# File lib/rtanque/shell.rb, line 34
def hits(bots, &on_hit)
  bots.each do |hit_bot|
    if hit_bot.position.within_radius?(self.position, Bot::RADIUS)
      self.dead!
      on_hit.call(self.bot, hit_bot) if on_hit
      break
    end
  end
end