Class: Quake::Sound::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/quake/sound/events.rb

Overview

Maps game events to sound file paths and plays them.

Constant Summary collapse

PICKUP_SOUNDS =

Item pickup sounds

{
  health: "items/health1.wav",
  armor: "items/armor1.wav",
  ammo: "weapons/lock4.wav",
  weapon: "weapons/pkup.wav",
  powerup: "items/protect.wav"
}.freeze
DOOR_SOUNDS =

Door/platform sounds

{
  open: "doors/medtry.wav",
  close: "doors/medclose.wav"
}.freeze
PLAT_SOUNDS =
{
  move: "plats/medplat1.wav",
  stop: "plats/medplat2.wav"
}.freeze
PLAYER_SOUNDS =

Player sounds

{
  jump: "player/plyrjmp8.wav",
  land: "player/land.wav",
  water_enter: "player/inh2o.wav",
  water_exit: "player/inlava.wav"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(mixer) ⇒ Events

Returns a new instance of Events.



35
36
37
# File 'lib/quake/sound/events.rb', line 35

def initialize(mixer)
  @mixer = mixer
end

Instance Method Details

#on_door(action) ⇒ Object



45
46
47
48
49
# File 'lib/quake/sound/events.rb', line 45

def on_door(action)
  return unless @mixer&.loaded?
  sound = DOOR_SOUNDS[action]
  @mixer.play(sound) if sound
end

#on_pickup(event) ⇒ Object



39
40
41
42
43
# File 'lib/quake/sound/events.rb', line 39

def on_pickup(event)
  return unless @mixer&.loaded?
  sound = PICKUP_SOUNDS[event[:type]]
  @mixer.play(sound) if sound
end

#on_player(action) ⇒ Object



51
52
53
54
55
# File 'lib/quake/sound/events.rb', line 51

def on_player(action)
  return unless @mixer&.loaded?
  sound = PLAYER_SOUNDS[action]
  @mixer.play(sound) if sound
end