diff --git a/desktop/resources/outside-jail/fountain-2.ogg b/desktop/resources/outside-jail/fountain-2.ogg new file mode 100644 index 00000000..e287eacb Binary files /dev/null and b/desktop/resources/outside-jail/fountain-2.ogg differ diff --git a/desktop/resources/outside-jail/fountain-2.wav b/desktop/resources/outside-jail/fountain-2.wav new file mode 100644 index 00000000..53ea62e4 Binary files /dev/null and b/desktop/resources/outside-jail/fountain-2.wav differ diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 174591f4..a93b9ce1 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -607,13 +607,16 @@ (>= (get-in entities [:fade :opacity]) 1.0)) (terminate [this screen entities] - (stop screen (if-let [next-time (get-in entities [:state :next-time])] - (-> entities - (assoc-in [:state :time] next-time) - (assoc-in [:state :next-time] nil)) - entities) - :ego - :face face)) + (let [entities (stop screen (if-let [next-time (get-in entities [:state :next-time])] + (-> entities + (assoc-in [:state :time] next-time) + (assoc-in [:state :next-time] nil)) + entities) + :ego + :face face)] + (if-let [stop-fn (get-in entities [:room :stop-fn])] + (stop-fn screen entities) + entities))) (can-skip? [this screen entities] false)) (run-action entities diff --git a/desktop/src-common/advent/screens/rooms/outside_jail.clj b/desktop/src-common/advent/screens/rooms/outside_jail.clj index 7afb3e26..11582830 100644 --- a/desktop/src-common/advent/screens/rooms/outside_jail.clj +++ b/desktop/src-common/advent/screens/rooms/outside_jail.clj @@ -81,6 +81,9 @@ (actions/walk-straight-to entities :ego [142 96]) (actions/talk entities :ego "This must be Frankie Rockfist's secret stash!"))) +(defn fountain-vol [entities] + (utils/proximity-volume entities [172 120] :scale 0.5)) + (defn make [screen] (let [guard-sheet (texture! (texture "inside-cafeteria/ladder-guard.png") :split 37 87) guard-stand (animation 0.1 [(aget guard-sheet 0 0)]) @@ -192,6 +195,8 @@ :y 140 :baseline 114) :axe (assoc (texture "outside-jail/axe.png") :x 213 :y 63 :baseline 176 :night-profile :sprite)} + :fountain-sound {:sound (sound "outside-jail/fountain-2.ogg") + :id nil} @@ -224,11 +229,24 @@ :collision "outside-jail/collision.png" :scale-fn (utils/scaler-fn-with-baseline 40 0.001 1.3) :start-pos [145 15] + + :update-fn (fn [_ entities] + (when-let [fountain-sound-id (get-in entities [:room :fountain-sound :id])] + (sound! (get-in entities [:room :fountain-sound :sound]) :set-volume fountain-sound-id (fountain-vol entities))) + entities) + + :stop-fn (fn [_ entities] + (when-let [fountain-sound-id (get-in entities [:room :fountain-sound :id])] + (sound! (get-in entities [:room :fountain-sound :sound]) :stop fountain-sound-id)) + entities) + :apply-state (fn [_ entities] + (as-> entities entities - (if (= :night (get-in entities [:state :time])) - (make-night entities) - entities) - (if (get-in entities [:state :dropped-ball?]) - (update-in entities [:room :entities :guard] #(actions/start-animation % :sleep)) - entities)))))) + (assoc-in entities [:room :fountain-sound :id] (sound! (get-in entities [:room :fountain-sound :sound]) :loop (fountain-vol entities))) + (if (= :night (get-in entities [:state :time])) + (make-night entities) + entities) + (if (get-in entities [:state :dropped-ball?]) + (update-in entities [:room :entities :guard] #(actions/start-animation % :sleep)) + entities)))))) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index b82892b1..74f17aeb 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -654,17 +654,11 @@ void main() ((set (keys anim-sound-frames)) anim)) (when-let [[snd vol-scale] (get-in anim-sound-frames [anim current-frame-index])] (let [vol (if (= target :ego) - (* (/ (get-in entities [:room :entities :ego :scale-x]) 1.5) 0.75) - (max 0.0 - (- 1.0 (/ (utils/dist x y - (get-in entities [:room :entities :ego :x]) - (get-in entities [:room :entities :ego :y]) - :y-sign 2.0 - :x-sign (/ 1.0 (get-in entities [:room :entities :ego :scale-x]))) - 175.0)))) - pan (/ (- (:x e) 160 ) 160) - vol (* vol vol-scale) - vol (max vol 0.005)] + (-> (* (/ (get-in entities [:room :entities :ego :scale-x]) 1.5) 0.75) + (* (or vol-scale 1.0)) + (utils/clamp-volume)) + (utils/proximity-volume entities [x y] :scale vol-scale)) + pan (/ (- (:x e) 160 ) 160)] (sound! (or (snd e) (snd (:sounds entities))) :play (utils/current-sound-volume vol) 1.0 pan)))))) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index f4374ca9..20c776f1 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -239,3 +239,17 @@ (def default-night-merge {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 1.0 :hue-amount 1.0}) (def default-night-merge-sprite {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 0.3 :hue-amount 0.4}) + +(defn clamp-volume [vol] + (max vol 0.005)) + +(defn proximity-volume [entities [x y] & {:keys [scale]}] + (-> (max 0.0 + (- 1.0 (/ (dist x y + (get-in entities [:room :entities :ego :x]) + (get-in entities [:room :entities :ego :y]) + :y-sign 2.0 + :x-sign (/ 1.0 (get-in entities [:room :entities :ego :scale-x]))) + 175.0))) + (* (or scale 1.0)) + (clamp-volume)))