explosion.rb 753 Bytes
class Explosion < Drawable

  include Rubygame

  DEFAULTS = { image: "explosion.png", zoom: 0.5, sound: "explosion.wav", volume: 0.5, ctype: :explosion}

  attr_accessor :image, :size
  def initialize game, opts = {}, &block
    opts = DEFAULTS.merge(opts)
    super(game, opts)
    @frame = 0
    @block = block
    @length = 20
    unless game.options[:mute]
      @sound = Music[options[:sound]]
      @sound.volume = options[:volume]
      @sound.play(fade_in: 0.0, repeats: 0)
    end
  end

  def draw screen
    destroy  if @frame >= @length - 2
    s = @surface.zoom(options[:zoom])
    s.blit(screen, pos.sub(s.size.div(2)))
    options[:zoom] += 0.025
    @frame += 1
  end

  def destroy
    @block.call(self)  if @block
    hide
  end

end