sound volume!

This commit is contained in:
2015-03-04 13:37:20 -08:00
parent bed3c16b27
commit 54f6b25b39
20 changed files with 354 additions and 37 deletions

View File

@@ -482,7 +482,7 @@
(defn give [entities item]
(run-action entities
(begin [this screen entities]
(sound! (sound "pickup.mp3") :play)
(sound! (sound "pickup.mp3") :play (utils/current-sound-volume))
(-> entities
(update-in [:state :inventory] #(conj % item))
@@ -552,7 +552,7 @@
(let [entities (-> entities
(assoc-in [:music-override :value] new-music)
(assoc-in [:volume :value] 1.0))]
(music! (utils/get-current-music entities) :set-volume 1.0)
(music! (utils/get-current-music entities) :set-volume (utils/current-music-volume))
(music! (utils/get-current-music entities) :play)
entities))

View File

@@ -268,7 +268,7 @@
(if (get-in @entities [:room :entities :ladder])
(do (actions/talk entities :ego "I think he's going for it!")
(actions/play-animation entities :ego :cat-toy-first-half :stop? false)
(sound! (sound "cat-tree/cat.ogg") :play)
(sound! (sound "cat-tree/cat.ogg") :play (utils/current-sound-volume))
(actions/walk-straight-to entities :cat [138 40] :update-baseline? false :speed 3)
(actions/play-animation entities :ego :cat-toy-last-half)
(actions/play-animation entities :grandma :squat-1 :stop? false)
@@ -283,7 +283,7 @@
:grandma "Come here young man.")
(actions/walk-straight-to entities :ego [133 35])
(actions/talk entities :grandma "For your impressive display of courage and bravery, I give you this. ")
(sound! (sound "cat-tree/kiss.ogg") :play)
(sound! (sound "cat-tree/kiss.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :grandma :kiss)
(actions/play-animation entities :ego :get-sick :stop? false)
(actions/walk-straight-to entities :ego [165 45])

View File

@@ -211,7 +211,7 @@
(actions/talk entities :ego "I'll just try one of these mints.")
(actions/play-animation entities :ego :reach)
(actions/update-state entities (fn [s] (assoc s :mints-eaten (inc (s :mints-eaten)))))
(sound! (sound (str "inside-antique/fire-" (get-in @entities [:state :mints-eaten]) ".ogg")) :play)
(sound! (sound (str "inside-antique/fire-" (get-in @entities [:state :mints-eaten]) ".ogg")) :play (utils/current-sound-volume))
(actions/play-animation entities :ego [:fire (get-in @entities [:state :mints-eaten])])
(actions/talk entities :ego "WOWZA! Those are hot.")
(when (= 3 (get-in @entities [:state :mints-eaten]))

View File

@@ -59,7 +59,7 @@
(if (actions/has-item? @entities :flask-1-strength)
(do
(actions/do-dialogue entities :ego "One sec.")
(sound! (sound "ego/potion.ogg") :play)
(sound! (sound "ego/potion.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :ego :grow :stop? false)
(play-battle entities :win)
(actions/do-dialogue entities

View File

@@ -29,7 +29,7 @@
(begin [this screen entities]
(particle-effect! (get-in entities [:room :entities :appear]) :reset)
(particle-effect! (get-in entities [:room :entities :appear]) :start)
(sound! (sound "inside-house/disappear.ogg") :play)
(sound! (sound "inside-house/disappear.ogg") :play (utils/current-sound-volume))
(-> entities
(assoc-in [:tweens :bloodclot-head-appear]
(tween/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 0.0 1.0 1.0 :ease tween/ease-in-quadratic))
@@ -101,7 +101,7 @@
:game-player "I don't have the might or courage required to pull the sword and fulfill the prophecy. "
:game-player "The knights of Remington have muscles the size of tree trunks."
:game-player "But me...")
(sound! (sound "inside-castle/flex.ogg") :play)
(sound! (sound "inside-castle/flex.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :game-player :flex)
(actions/do-dialogue entities :game-player "I'd never be able to prove my strength."))
:choices actions/previous-choices}
@@ -250,7 +250,7 @@
:cursor :up
:script (actions/get-script entities
(actions/walk-to entities :ego [182 90] :face :left)
(sound! (sound "door.ogg") :play)
(sound! (sound "door.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :ego :reach)
(if (= :night (get-in @entities [:state :time]))
(actions/talk entities :ego "It's locked.")
@@ -443,12 +443,7 @@
entities)
(if (= :night (get-in entities [:state :time]))
(make-night entities)
entities)
#_(let [chorus
instance (sound! chorus :loop 0.0)]
(-> entities
(assoc-in [:room :chorus :sound] chorus)
(assoc-in [:room :chorus :instance] instance)))))
entities)))
:update-fn (fn [screen entities]
#_(when (and (actions/has-obtained? entities :sword)
(get-in entities [:room :entities :magic])
@@ -464,8 +459,8 @@
(if (:instance chorus)
(do (sound! (:sound chorus) :set-volume
(:instance chorus)
chorus-volume)
(utils/current-sound-volume chorus-volume))
entities)
(assoc-in entities [:room :chorus :instance] (sound! (:sound chorus) :loop
chorus-volume)))))))
(utils/current-sound-volume chorus-volume))))))))
:start-pos [245 90])))

View File

@@ -95,7 +95,7 @@
:wizard "Ok, I'll deliver them myself. Don't touch anything while I'm gone.")
(actions/update-state entities (fn [s] (assoc s :mints-eaten 0
:wizard-left? true)))
(sound! (sound "inside-house/disappear.ogg") :play)
(sound! (sound "inside-house/disappear.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :wizard :disappear :stop? false)
(actions/remove-entity entities :wizard))}
"Nevermind."

View File

@@ -279,7 +279,7 @@
entities
(actions/walk-to entities :ego [267 90])
(actions/talk entities :ego (str "Anyone home?"))
(sound! (sound "door.ogg") :play)
(sound! (sound "door.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :ego :reach)
(if (= :night (get-in @entities [:state :time]))
(actions/talk entities :ego "It's locked.")

View File

@@ -32,7 +32,7 @@
(not (get-in entities [:state :blergh-dead?]))
(actions/has-item? entities :magic-slingshot))
((actions/get-script entities
(sound! (sound "space/shock.ogg") :play)
(sound! (sound "space/shock.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :bloodclot-head :shoot :stop? false)
(actions/begin-animation entities :bloodclot-head :keep-shoot)
(actions/do-dialogue entities :bloodclot-head "Dang! Come a little closer!"))
@@ -56,7 +56,7 @@
(begin [this screen entities]
(particle-effect! (get-in entities [:room :entities :appear]) :reset)
(particle-effect! (get-in entities [:room :entities :appear]) :start)
(sound! (sound "inside-house/disappear.ogg") :play)
(sound! (sound "inside-house/disappear.ogg") :play (utils/current-sound-volume))
(-> entities
(assoc-in [:tweens :bloodclot-head-appear]
(tween/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 1.0 0.0 1.0 :ease tween/ease-in-cubic))
@@ -85,7 +85,7 @@
(actions/run-action entities
(begin [this screen entities]
(sound! (sound "space/jump.ogg") :play)
(sound! (sound "space/jump.ogg") :play (utils/current-sound-volume))
(-> entities
(assoc-in [:room :entities :cloud] (assoc (texture "space/cloud.png")
:x (- (get-in entities [:room :entities :ego :x]) 10)
@@ -132,7 +132,7 @@
(actions/run-action entities
(begin [this screen entities]
(sound! (sound "space/swingsword.ogg") :play)
(sound! (sound "space/swingsword.ogg") :play (utils/current-sound-volume))
(-> entities
(update-in [:room :entities :ego]
#(actions/start-animation screen % :swing))
@@ -232,7 +232,7 @@
(actions/do-dialogue entities :bloodclot-head "Ha ha ha! Is that the best you can do?"
:bloodclot-head "Take this!")
(sound! (sound "space/shock.ogg") :play)
(sound! (sound "space/shock.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :bloodclot-head :shoot :stop? false)
(actions/begin-animation entities :bloodclot-head :keep-shoot)
(actions/play-animation entities :ego :shock :stop? false)

View File

@@ -82,7 +82,7 @@
(when (:shown? entities)
(let [[x y] (utils/unproject screen)]
(if-let [button (get-button [x y])]
(do (sound! (:sound button) :play)
(do (sound! (:sound button) :play (utils/current-sound-volume))
(let [new-state (update-in entities [:button-choices] #(conj % (:id button)))]
(cond (= [4 2 1 5 3] (:button-choices new-state))

View File

@@ -104,7 +104,7 @@
(defn drink-blergh [entities]
(actions/walk-straight-to entities :ego [205 45])
(sound! (sound "ego/potion.ogg") :play)
(sound! (sound "ego/potion.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :ego :grow :stop? false)
(actions/do-dialogue entities
:blergh "What this? A potion of strength?"
@@ -290,7 +290,7 @@
:else
(do
(actions/talk entities :ego "I'll just take a sip!")
(sound! (sound "ego/potion.ogg") :play)
(sound! (sound "ego/potion.ogg") :play (utils/current-sound-volume))
(actions/play-animation entities :ego :grow :stop? false))))
:recipe (actions/get-script entities (actions/do-dialogue entities
:ego "The recipe says:"
@@ -402,7 +402,7 @@
(defn fade-in-first-time-if-necessary [screen entities]
(if (not (get-in entities [:started? :value]))
(do (music! (utils/get-current-music entities) :set-volume (get-in entities [:volume :value]))
(do (music! (utils/get-current-music entities) :set-volume (utils/current-music-volume (get-in entities [:volume :value])))
(utils/play-sound (get-in entities [:musics (actions/get-music (get-in entities [:room :music]) (get-in entities [:state :time]))]))
(assoc entities
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0 :ease tween/ease-in-cubic)
@@ -429,7 +429,7 @@
vol (* vol vol-scale)
vol (max vol 0.005)]
(sound! (or (snd e)
(snd (:sounds entities))) :play vol 1.0 pan))))))
(snd (:sounds entities))) :play (utils/current-sound-volume vol) 1.0 pan))))))
(defn update-from-room [screen entities]
(if-let [update-fn (get-in entities [:room :update-fn])]
@@ -629,7 +629,7 @@
(play-key-sounds entities))
(doseq [m (vals (get-in entities [:musics]))]
(when m
(music! m :set-volume (get-in entities [:volume :value]))))
(music! m :set-volume (utils/current-music-volume (get-in entities [:volume :value])))))
(doseq [e (sort-by :baseline all-entities)]
(if (:parallax e)
(render-parallax screen e)

View File

@@ -36,6 +36,7 @@
(fn [screen entities]
(let [cam (orthographic)
viewport (FitViewport. 1280 960 cam)]
(utils/load-settings!)
(update! screen :renderer (stage) :camera cam :viewport viewport)
(.apply viewport)
(let [font (utils/get-font "ego/font.fnt")
@@ -43,7 +44,8 @@
start-playing (center start-playing)
quit (assoc (label "Quit thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 50)
quit (center quit)
music (utils/make-music "intro.ogg")]
music (utils/make-music "intro.ogg")
ui-skin (skin "ui/ui.json")]
(label! start-playing :set-alignment Align/center)
{:overlay (assoc (texture "title-overlay.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0)
@@ -51,6 +53,16 @@
:scale-x 80
:scale-y 80
:opacity 1.0)
:music-volume-slider (assoc (slider {:min 0 :max 100 :step 1} ui-skin :set-value (:music-volume @utils/settings))
:x ( - (/ (game :width) 2)
150)
:width 300
:y 200)
:sound-volume-slider (assoc (slider {:min 0 :max 100 :step 1 } ui-skin :set-value (:sound-volume @utils/settings))
:width 300
:x ( - (/ (game :width) 2)
150)
:y 150)
:viewport viewport
:font font
:music music
@@ -60,8 +72,7 @@
:quit quit
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
:finish #(do (utils/play-sound (:music %)) %)
:ease tween/ease-in-quadratic)}
})))
:ease tween/ease-in-quadratic)}})))
:on-render
(fn [screen [entities]]
@@ -71,8 +82,8 @@
(clear!)
(let [entities (utils/apply-tweens screen entities (:tweens entities))]
(music! (:music entities) :set-volume 0.0 #_(:volume entities))
(render! screen [(:overlay entities) (:start-playing entities) (:quit entities) (:fade entities)])
(music! (:music entities) :set-volume (utils/current-music-volume (:volume entities)))
(render! screen [(:overlay entities) (:start-playing entities) (:quit entities) (:music-volume-slider entities) (:sound-volume-slider entities) (:fade entities) ])
entities))
:show-screen (fn [entities]
@@ -83,6 +94,14 @@
(style-label (:start-playing entities) (get-in entities [:font]) [x y])
(style-label (:quit entities) (get-in entities [:font]) [x y])
entities))
:on-ui-changed
(fn [screen [entities]]
(swap! utils/settings
assoc
:music-volume (slider! (:music-volume-slider entities) :get-value)
:sound-volume (slider! (:sound-volume-slider entities) :get-value))
(utils/save-settings!)
entities)
:on-touch-up (fn [screen [entities]]
(let [[x y] (utils/unproject screen)]
@@ -97,7 +116,7 @@
entities)
:ease tween/ease-in-cubic))
(assoc-in [:tweens :fade-out-music]
(tween/tween :fade-out-music screen [:volume] 1.0 0.0 1.8)))
(tween/tween :fade-out-music screen [:volume] 1.0 0.0 1.0)))
(utils/intersects? (:quit entities) [x y])
(-> entities
(assoc-in [:tweens :fade-out]
@@ -111,6 +130,5 @@
nil)))
:on-resize (fn [screen [entities]]
(println (game :width) (game :height) (:width screen) (:height screen))
(.update (:viewport entities) (game :width) (game :height) true)
nil))

View File

@@ -5,6 +5,7 @@
[play-clj.utils :refer :all]
[play-clj.math :refer :all]
[play-clj.g2d :refer :all]
[clojure.java.io :as io]
[clojure.edn :as edn])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion]
@@ -18,6 +19,19 @@
(def +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :watch :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot])
(def settings (atom {:music-volume 50.0
:sound-volume 75.0}))
(defn current-music-volume [& [factor]]
(* (Math/pow (/ (:music-volume @settings) 100.0) 2)
0.25
(or factor 1.0)))
(defn current-sound-volume [& [factor]]
(* (Math/pow (/ (:sound-volume @settings) 100.0) 2)
0.5
(or factor 1.0)))
(defn cursor [filename which]
(let [scale 2
base-cursor (pixmap filename)
@@ -36,6 +50,13 @@
(defn load []
(assoc (edn/read-string (slurp "save.edn")) :active? true))
(defn load-settings! []
(when (.exists (io/file "settings.edn"))
(reset! settings (edn/read-string (slurp "settings.edn")))))
(defn save-settings! []
(spit "settings.edn" @settings))
(defn get-font [filename]
(let [font (bitmap-font filename)
tr (bitmap-font! font :get-region)