sounds are now updated every frame.

This commit is contained in:
Bryce Covert
2015-10-07 17:29:53 -07:00
parent 8e12d2df0b
commit b87b8aa171
6 changed files with 88 additions and 38 deletions

View File

@@ -399,3 +399,40 @@
(.getDeclaredField (name "config"))
(doto (.setAccessible true))
(.get Gdx/graphics))) 60))))
(defn get-sound-volume [entities target vol-scale [x y]]
(if (= target :ego)
(-> (* (/ (get-in entities [:room :entities :ego :scale-x]) 1.5) 0.75)
(* (or vol-scale 1.0))
(clamp-volume))
(proximity-volume entities [x y] :scale vol-scale)))
(defn get-sound-pan [x]
(/ (- x 160 ) 160))
(defn play-sound!
([screen entities snd target vol-scale [x y]]
(play-sound! screen entities snd target vol-scale [x y] :once))
([screen entities snd target vol-scale [x y] type]
(let [vol (get-sound-volume entities target vol-scale [x y])
pan (get-sound-pan x)
sound-id (if (= :once type)
(sound! snd :play (current-sound-volume vol) 1.0 pan)
(sound! snd :loop (current-sound-volume vol) 1.0 pan)) ]
(update-in entities [:current-sounds :value]
conj {:id sound-id
:sound snd
:loc [x y]
:vol-scale vol-scale
:type type
:ends-at (if (= type :once)
(+ (:total-time screen) (sound! snd :duration))
nil)
:target target}))))
(defn stop-all-sounds! [entities]
(doseq [snd (get-in entities [:current-sounds :value])]
(sound! (:sound snd) :stop (:id snd))))