Class: Doom::Game::SoundEngine
- Inherits:
-
Object
- Object
- Doom::Game::SoundEngine
- Defined in:
- lib/doom/game/sound_engine.rb
Overview
Plays sound effects for game events.
Constant Summary collapse
- WEAPON_SOUNDS =
Weapon fire sounds
{ PlayerState::WEAPON_FIST => 'DSPUNCH', PlayerState::WEAPON_PISTOL => 'DSPISTOL', PlayerState::WEAPON_SHOTGUN => 'DSSHOTGN', PlayerState::WEAPON_CHAINGUN => 'DSPISTOL', PlayerState::WEAPON_ROCKET => 'DSRLAUNC', PlayerState::WEAPON_PLASMA => 'DSPLASMA', PlayerState::WEAPON_BFG => 'DSBFG', PlayerState::WEAPON_CHAINSAW => 'DSSAWIDL', }.freeze
- MONSTER_SEE =
Monster see/activation sounds (from mobjinfo seesound)
{ 3004 => 'DSPOSIT1', # Zombieman 9 => 'DSSGTSIT', # Shotgun Guy 3001 => 'DSBGSIT1', # Imp 3002 => 'DSSGTSIT', # Demon 58 => 'DSSGTSIT', # Spectre 3003 => 'DSBRSSIT', # Baron 69 => 'DSBRSSIT', # Hell Knight 3005 => 'DSCACSIT', # Cacodemon 3006 => 'DSSKLATK', # Lost Soul 65 => 'DSPOSIT2', # Heavy Weapon Dude 16 => 'DSCYBSIT', # Cyberdemon 7 => 'DSSPISIT', # Spider Mastermind }.freeze
- MONSTER_DEATH =
Monster death sounds (from mobjinfo deathsound)
{ 3004 => 'DSPODTH1', # Zombieman 9 => 'DSSGTDTH', # Shotgun Guy 3001 => 'DSBGDTH1', # Imp 3002 => 'DSSGTDTH', # Demon 58 => 'DSSGTDTH', # Spectre 3003 => 'DSBRSDTH', # Baron 69 => 'DSBRSDTH', # Hell Knight 3005 => 'DSCACDTH', # Cacodemon 3006 => 'DSFIRXPL', # Lost Soul 65 => 'DSPODTH2', # Heavy Weapon Dude 16 => 'DSCYBDTH', # Cyberdemon 7 => 'DSSPIDTH', # Spider Mastermind }.freeze
- MONSTER_PAIN =
Monster pain sounds (from mobjinfo painsound)
{ 3004 => 'DSPOPAIN', # Zombieman 9 => 'DSPOPAIN', # Shotgun Guy 3001 => 'DSDMPAIN', # Imp 3002 => 'DSDMPAIN', # Demon 58 => 'DSDMPAIN', # Spectre 3003 => 'DSDMPAIN', # Baron 69 => 'DSDMPAIN', # Hell Knight 3005 => 'DSDMPAIN', # Cacodemon 3006 => 'DSDMPAIN', # Lost Soul 65 => 'DSPOPAIN', # Heavy Weapon Dude }.freeze
- MONSTER_ATTACK =
Monster attack sounds (from mobjinfo attacksound)
{ 3004 => 'DSPISTOL', # Zombieman: pistol 9 => 'DSSHOTGN', # Shotgun Guy: shotgun 3001 => 'DSFIRSHT', # Imp: fireball launch 3002 => 'DSSGTATK', # Demon: bite 58 => 'DSSGTATK', # Spectre: bite 3003 => 'DSFIRSHT', # Baron: fireball 69 => 'DSFIRSHT', # Hell Knight: fireball 3005 => 'DSFIRSHT', # Cacodemon: fireball 65 => 'DSSHOTGN', # Heavy Weapon Dude: chaingun burst }.freeze
Instance Method Summary collapse
- #chainsaw_hit ⇒ Object
- #door_close ⇒ Object
-
#door_open ⇒ Object
— Door/environment sounds —.
-
#explosion ⇒ Object
— Explosions / impacts —.
- #fireball_hit ⇒ Object
-
#initialize(sound_manager) ⇒ SoundEngine
constructor
A new instance of SoundEngine.
- #item_pickup ⇒ Object
- #menu_back ⇒ Object
-
#menu_move ⇒ Object
— Menu sounds —.
- #menu_select ⇒ Object
- #monster_attack(type) ⇒ Object
- #monster_death(type) ⇒ Object
- #monster_pain(type) ⇒ Object
-
#monster_see(type) ⇒ Object
— Monster sounds —.
- #noway ⇒ Object
- #oof ⇒ Object
- #platform_start ⇒ Object
- #platform_stop ⇒ Object
- #play(name, volume: 1.0, throttle: 0) ⇒ Object
- #player_death ⇒ Object
-
#player_pain ⇒ Object
— Player events —.
- #rocket_explode ⇒ Object
- #shotgun_cock ⇒ Object
- #switch_activate ⇒ Object
-
#weapon_fire(weapon) ⇒ Object
— Weapon events —.
- #weapon_pickup ⇒ Object
Constructor Details
#initialize(sound_manager) ⇒ SoundEngine
Returns a new instance of SoundEngine.
78 79 80 81 |
# File 'lib/doom/game/sound_engine.rb', line 78 def initialize(sound_manager) @sounds = sound_manager @last_played = {} # Throttle rapid repeats end |
Instance Method Details
#chainsaw_hit ⇒ Object
116 117 118 |
# File 'lib/doom/game/sound_engine.rb', line 116 def chainsaw_hit play('DSSAWFUL', throttle: 0.1) end |
#door_close ⇒ Object
150 151 152 |
# File 'lib/doom/game/sound_engine.rb', line 150 def door_close play('DSDORCLS', throttle: 0.2) end |
#door_open ⇒ Object
— Door/environment sounds —
146 147 148 |
# File 'lib/doom/game/sound_engine.rb', line 146 def door_open play('DSDOROPN', throttle: 0.2) end |
#explosion ⇒ Object
— Explosions / impacts —
188 189 190 |
# File 'lib/doom/game/sound_engine.rb', line 188 def explosion play('DSBAREXP') end |
#fireball_hit ⇒ Object
196 197 198 |
# File 'lib/doom/game/sound_engine.rb', line 196 def fireball_hit play('DSFIRXPL', throttle: 0.1) end |
#item_pickup ⇒ Object
129 130 131 |
# File 'lib/doom/game/sound_engine.rb', line 129 def item_pickup play('DSITEMUP', throttle: 0.1) end |
#menu_back ⇒ Object
102 103 104 |
# File 'lib/doom/game/sound_engine.rb', line 102 def play('DSSWTCHX') end |
#menu_move ⇒ Object
— Menu sounds —
94 95 96 |
# File 'lib/doom/game/sound_engine.rb', line 94 def play('DSPSTOP', throttle: 0.05) end |
#menu_select ⇒ Object
98 99 100 |
# File 'lib/doom/game/sound_engine.rb', line 98 def play('DSPISTOL') end |
#monster_attack(type) ⇒ Object
182 183 184 185 |
# File 'lib/doom/game/sound_engine.rb', line 182 def monster_attack(type) sound = MONSTER_ATTACK[type] play(sound, throttle: 0.1) if sound end |
#monster_death(type) ⇒ Object
172 173 174 175 |
# File 'lib/doom/game/sound_engine.rb', line 172 def monster_death(type) sound = MONSTER_DEATH[type] play(sound) if sound end |
#monster_pain(type) ⇒ Object
177 178 179 180 |
# File 'lib/doom/game/sound_engine.rb', line 177 def monster_pain(type) sound = MONSTER_PAIN[type] play(sound, throttle: 0.2) if sound end |
#monster_see(type) ⇒ Object
— Monster sounds —
167 168 169 170 |
# File 'lib/doom/game/sound_engine.rb', line 167 def monster_see(type) sound = MONSTER_SEE[type] play(sound, throttle: 0.5) if sound end |
#noway ⇒ Object
141 142 143 |
# File 'lib/doom/game/sound_engine.rb', line 141 def noway play('DSNOWAY', throttle: 0.3) end |
#oof ⇒ Object
137 138 139 |
# File 'lib/doom/game/sound_engine.rb', line 137 def oof play('DSOOF', throttle: 0.3) end |
#platform_start ⇒ Object
158 159 160 |
# File 'lib/doom/game/sound_engine.rb', line 158 def platform_start play('DSPSTART', throttle: 0.2) end |
#platform_stop ⇒ Object
162 163 164 |
# File 'lib/doom/game/sound_engine.rb', line 162 def platform_stop play('DSPSTOP', throttle: 0.2) end |
#play(name, volume: 1.0, throttle: 0) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/doom/game/sound_engine.rb', line 83 def play(name, volume: 1.0, throttle: 0) now = Time.now.to_f if throttle > 0 return if @last_played[name] && (now - @last_played[name]) < throttle end sample = @sounds[name] sample&.play(volume) @last_played[name] = now end |
#player_death ⇒ Object
125 126 127 |
# File 'lib/doom/game/sound_engine.rb', line 125 def player_death play('DSPLDETH') end |
#player_pain ⇒ Object
— Player events —
121 122 123 |
# File 'lib/doom/game/sound_engine.rb', line 121 def player_pain play('DSPLPAIN', throttle: 0.3) end |
#rocket_explode ⇒ Object
192 193 194 |
# File 'lib/doom/game/sound_engine.rb', line 192 def rocket_explode play('DSRXPLOD') end |
#shotgun_cock ⇒ Object
112 113 114 |
# File 'lib/doom/game/sound_engine.rb', line 112 def shotgun_cock play('DSSGCOCK', throttle: 0.3) end |
#switch_activate ⇒ Object
154 155 156 |
# File 'lib/doom/game/sound_engine.rb', line 154 def switch_activate play('DSSWTCHN') end |
#weapon_fire(weapon) ⇒ Object
— Weapon events —
107 108 109 110 |
# File 'lib/doom/game/sound_engine.rb', line 107 def weapon_fire(weapon) sound = WEAPON_SOUNDS[weapon] play(sound, throttle: 0.05) if sound end |
#weapon_pickup ⇒ Object
133 134 135 |
# File 'lib/doom/game/sound_engine.rb', line 133 def weapon_pickup play('DSWPNUP') end |