diff --git a/desktop/src-common/advent/screens/rooms/outside_castle.clj b/desktop/src-common/advent/screens/rooms/outside_castle.clj index ed866193..441cae45 100644 --- a/desktop/src-common/advent/screens/rooms/outside_castle.clj +++ b/desktop/src-common/advent/screens/rooms/outside_castle.clj @@ -257,7 +257,7 @@ steer-sheet (texture! (texture "outside-castle/steer.png") :split 50 35) steer-stand (animation 0.2 (for [i [0 0 0 0 0 0 0 0 0 1 0 2 0 1 0 2 0 1 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 3 3 3 0 0 0 0]] (aget steer-sheet 0 i))) - flies-stand (utils/make-anim "outside-castle/flies.png" [15 15] 0.075 [0 1 2 1])] + flies-stand (utils/make-anim "outside-castle/flies.png" [15 15] 0.075 (flatten (repeat 2 [0 1 2 1])))] (rooms/make :music {:day :town-2 :night :night :sunrise :night} :interactions {:right-dir {:box [300 40 320 140] @@ -295,7 +295,7 @@ :sunrise [(assoc (texture "outside-castle/background-sunrise.png") :x 0 :y 0 :baseline 0)]} :entities {:peddler (actions/start-animation screen (assoc (texture "outside-castle/peddler.png") :x 110 :y 90 :baseline 150 :anim nil - :anim-sound-frames {peddler-stand {23 :scratch}} + :anim-sound-frames {peddler-stand {23 [:scratch 1.0]}} :scratch (sound "scratch.ogg") :talk peddler-talk :stand peddler-stand :talk-color (color 1.0 0.9 0.4 1.0) @@ -360,6 +360,7 @@ :anim flies-stand :anim-start 0 :baseline 240 + :sound (sound "outside-castle/flies.ogg") :scripts {:sack-lunch (actions/get-script entities (actions/walk-to entities :ego [168 150] :face :right) (actions/talk entities :ego "Maybe I can catch some of these flies.") @@ -368,7 +369,8 @@ (actions/talk entities :ego "I think it's working!") (actions/play-animation entities :ego :squat) (actions/give entities :flies) - (actions/talk entities :ego "Hopefully they won't fly out of my backpack."))})} + (actions/talk entities :ego "Hopefully they won't fly out of my backpack."))} + :anim-sound-frames {flies-stand {0 [:sound 0.33]}})} :note (rooms/make-entity :note (assoc (texture "outside-castle/note.png") :x 198 :y 66 :baseline 174 :script (actions/get-script entities diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 163068d6..e9f12244 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -295,10 +295,10 @@ nil)) :x (first start-pos) :y (last start-pos) :id "ego"} - ego (assoc ego :anim-sound-frames {(get-in ego [:left :walk]) {2 :step-sound-1 - 6 :step-sound-2} - (get-in ego [:right :walk]) {2 :step-sound-1 - 6 :step-sound-2}} + ego (assoc ego :anim-sound-frames {(get-in ego [:left :walk]) {2 [:step-sound-1 1.0] + 6 [:step-sound-2 0.8]} + (get-in ego [:right :walk]) {2 [:step-sound-1 1.0] + 6 [:step-sound-2 0.8]}} :anim-merges {(get-in ego [:right :shock]) {:origin-x 15} :default {:origin-x 9}})] (actions/start-animation screen @@ -370,11 +370,22 @@ :seen-intro? false})) (defn play-key-sounds [entities] - (doseq [{:keys [previous-frame-index current-frame-index anim-sound-frames anim] :as e} (vals entities)] + (doseq [[target {:keys [previous-frame-index current-frame-index anim-sound-frames anim x y] :as e}] entities] (when (and (not= previous-frame-index current-frame-index) ((set (keys anim-sound-frames)) anim)) - (when-let [snd (get-in anim-sound-frames [anim current-frame-index])] - (sound! (snd e) :play (* (/ (get-in entities [:ego :scale-x]) 1.5) 0.75)))))) + (when-let [[snd vol-scale] (get-in anim-sound-frames [anim current-frame-index])] + (let [vol (if (= target :ego) + (* (/ (get-in entities [:ego :scale-x]) 1.5) 0.75) + (max 0.0 + (- 1.0 (/ (utils/dist x y + (get-in entities [:ego :x]) + (get-in entities [:ego :y]) + :y-sign 2.0 + :x-sign (/ 1.0 (get-in entities [:ego :scale-x]))) + 175.0)))) + vol (* vol vol-scale)] + (when (> vol 0.05) + (sound! (snd e) :play vol))))))) (defscreen scene diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index b5aea6f1..c0910aed 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -62,9 +62,11 @@ (.r))] (+ (* percent-complete (- maximum-size minimum-size)) minimum-size))))) -(defn dist [x1 y1 x2 y2] - (let [dx (- x1 x2) - dy (- y1 y2)] +(defn dist [x1 y1 x2 y2 & {:keys [y-sign x-sign]}] + (let [y-sign (or y-sign 1.0) + x-sign (or x-sign 1.0) + dx (* (- x1 x2) x-sign) + dy (* y-sign (- y1 y2))] (Math/sqrt (+ (* dx dx) (* dy dy)))))