bullet.rb 542 Bytes
class Bullet < Movable

  def initialize game, opts = {}
    opts.merge!(m: 10.0, ctype: :bullet)
    super(game, opts)
  end

  def draw screen
    return hide if pos[0] < (0 - size[0]) || pos[1] < (0 - size[1]) ||
      pos[0] > @game.screen.size[0] || pos[1] > @game.screen.size[1]
    super screen
  end

  def hit ship
    p = pos; @options[:dir] == :up ? p[1] -= @shape.r : p[1] += @shape.r
    Explosion.new(@game, p: p).show
    ship.take_damage(options[:damage])
    @options[:shooter].hit(ship, options[:damage])
    hide
  end
end