Created
February 15, 2021 20:06
-
-
Save cbilski/71ad02fa880fba33b2c7d777af3c7594 to your computer and use it in GitHub Desktop.
A sample sound effects class for DragonRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sfx | |
def initialize(args) | |
@args = args | |
@music_mast = 0.5 | |
@sfx_mast = 0.5 | |
end | |
def stop(sound_id) | |
if @args.audio.key?(sound_id) | |
@args.audio.delete(sound_id) | |
end | |
end | |
def loop(sound_id, p1 = nil) | |
case sound_id | |
when :music_bed | |
loopee = @args.audio[sound_id] | |
if (loopee.nil?) | |
vol = 1.0 | |
@args.audio[sound_id] = { input: "/music/music-bed-tense.ogg", gain: @music_mast * vol, pitch: 1.0, looping: true, paused: false } | |
end | |
else | |
end | |
end | |
def play(sound_id, p1 = nil) | |
case sound_id | |
when :craft_weapon_part | |
rand_id = rand(5) + 1 | |
wav_vol = 0.9 | |
@args.audio[:craft_weapon_part_internal1] = { input: "sounds/smithy/forge/weapon-#{rand_id}.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
rand_id = rand(2) + 1 | |
wav_vol = 0.9 | |
@args.audio[:craft_weapon_part_internal2] = { input: "sounds/smithy/forge/weapon-low-#{rand_id}.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :craft_weapon_complete | |
wav_vol = 0.8 | |
@args.audio[sound_id] = { input: "sounds/smithy/forge/item-completed.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :feedback_bad | |
wav_vol = 1.0 | |
@args.audio[sound_id] = { input: "sounds/smithy/forge/abs-cancel-6-verbed.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :monster_dying | |
rand_id = rand(5) + 1 | |
wav_vol = 1.0 | |
@args.audio[sound_id] = { input: "sounds/monster/beast/beast-0#{rand_id}.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :next_monster | |
wav_vol = 1.0 | |
@args.audio[sound_id] = { input: "sounds/encounter/start/encounter-start-#{p1}.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :reset_progress | |
wav_vol = 1.0 | |
@args.audio[sound_id] = { input: "sounds/monster/beast/beast-05.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :ui_deselect | |
wav_vol = 1.0 | |
@args.audio[sound_id] = { input: "sounds/ui/selection/unselected.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :ui_select | |
wav_vol = 1.0 | |
@args.audio[sound_id] = { input: "sounds/ui/selection/selected.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :ui_menu_mouseover | |
wav_vol = 1.0 | |
@args.audio[sound_id] = { input: "sounds/smithy/forge/ui-mouse-over-2.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :encounter_end | |
wav_vol = 1.5 | |
@args.audio[sound_id] = { input: "sounds/monster/beast/beast-05.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :encounter_win | |
wav_vol = 1.25 | |
@args.audio[sound_id] = { input: "sounds/encounter/start/encounter-win.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :encounter_lose | |
wav_vol = 1.75 | |
@args.audio[sound_id] = { input: "sounds/encounter/start/encounter-lose.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :howto | |
rand_id = rand(2) + 1 | |
wav_vol = 1.0 | |
@args.audio[sound_id] = { input: "sounds/smithy/forge/howto-#{rand_id}.wav", gain: @sfx_mast * wav_vol, pitch: 1.0, looping: false, paused: false } | |
when :music_bed | |
vol = 1.0 | |
@args.audio[sound_id] = { input: "music/music_1.ogg", gain: @music_mast * vol, pitch: 1.0, looping: false, paused: false } | |
else | |
# default? clown horn? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment