Sha256: e8aeb39614cb9cebb0696a5230ba52ed093b9d131e093e5aeb28c6aa7887e648

Contents?: true

Size: 1.21 KB

Versions: 18

Compression:

Stored size: 1.21 KB

Contents

require "java"

# Sound snippets from everywhere (JRuby-only!):

def sound_alarm beeps = 3
  beeps.times do
    java.awt.Toolkit.getDefaultToolkit.beep
    sleep 0.5
  end
end

; 3.times {java.awt.Toolkit.getDefaultToolkit.beep; p "oo"; sleep 1}

# Sound snippets from everywhere (JRuby-only!):

java_import javax.sound.sampled.AudioSystem
java_import javax.sound.sampled.Clip
java_import javax.sound.sampled.DataLine

class Sound
  attr_accessor :clip

  def self.load_sound(file_name)
    sound = new

    url = java.net.URL.new("file://" + ASSETS_DIR + file_name) # nasty little hack due to borked get_resource (means applet won't be easy..)
    ais = AudioSystem.get_audio_input_stream(url)
    info = DataLine::Info.new(Clip.java_class, ais.format)
    clip = AudioSystem.get_line(info)
    clip.open(ais)
    clip.extend JRuby::Synchronized
    sound.clip = clip

    sound
  end

  def play
    if clip
      Thread.new do
        clip.stop
        clip.frame_position = 0
        clip.start
      end
    end
  end

  %w{altar bosskill click1 click2 hit hurt hurt2 kill death splash key pickup roll shoot treasure crumble slide cut thud ladder potion}.each do |name|
    const_set name.upcase, load_sound("/snd/#{name}.wav")
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
releaseable-0.0.22 lib/releaseable/sound.rb
releaseable-0.0.21 lib/releaseable/sound.rb
releaseable-0.0.20 lib/releaseable/sound.rb
releaseable-0.0.18 lib/releaseable/sound.rb
releaseable-0.0.17 lib/releaseable/sound.rb
releaseable-0.0.16 lib/releaseable/sound.rb
releaseable-0.0.15 lib/releaseable/sound.rb
releaseable-0.0.14 lib/releaseable/sound.rb
releaseable-0.0.12 lib/releaseable/sound.rb
releaseable-0.0.11 lib/releaseable/sound.rb
releaseable-0.0.10 lib/releaseable/sound.rb
releaseable-0.0.9 lib/releaseable/sound.rb
releaseable-0.0.8 lib/releaseable/sound.rb
releaseable-0.0.7 lib/releaseable/sound.rb
releaseable-0.0.6 lib/releaseable/sound.rb
releaseable-0.0.4 lib/releaseable/sound.rb
releaseable-0.0.3 lib/releaseable/sound.rb
releaseable-0.0.2 lib/releaseable/sound.rb