sounds are now updated every frame.
This commit is contained in:
@@ -8,7 +8,6 @@ PROGRAMMING
|
||||
+ behind house left direction not great
|
||||
+ spying broken
|
||||
+ still can get into dialogue deadlock somehow
|
||||
+ Go backwards on load.
|
||||
|
||||
IOS
|
||||
+ all mp3s
|
||||
|
||||
@@ -649,11 +649,13 @@
|
||||
:none))
|
||||
(run-action entities
|
||||
(begin [this screen entities]
|
||||
(utils/stop-all-sounds! entities)
|
||||
(let [ego (get-in entities [:room :entities :ego])
|
||||
old-music (get-music (get-in entities [:room :music]) (get-in entities [:state :time]))
|
||||
entities (as-> entities e
|
||||
(assoc-in e [:room] (get-in entities [:rooms new-background]))
|
||||
(assoc-in e [:room :entities :ego] ego)
|
||||
(assoc-in e [:current-sounds :value] [])
|
||||
(if between (between screen e) e)
|
||||
(assoc-in e [:state :last-room] new-background)
|
||||
(assoc-in e [:tweens :fade-in] (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 time))
|
||||
|
||||
@@ -93,9 +93,6 @@
|
||||
(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! (utils/get-texture "inside-cafeteria/ladder-guard.png") :split 37 87)
|
||||
guard-stand (animation 0.1 [(aget guard-sheet 0 0)])
|
||||
@@ -281,21 +278,13 @@
|
||||
: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]
|
||||
:apply-state (fn [screen entities]
|
||||
(utils/fast-forward-particle (get-in entities [:room :entities :outside-particles]))
|
||||
|
||||
(as-> entities entities
|
||||
(assoc-in entities [:room :fountain-sound :id] (sound! (get-in entities [:room :fountain-sound :sound]) :loop (fountain-vol entities)))
|
||||
(utils/play-sound! screen entities (get-in entities [:room :fountain-sound :sound])
|
||||
:fountain 0.5 [172 120] :loop)
|
||||
|
||||
(if (= :night (get-in entities [:state :time]))
|
||||
(make-night entities)
|
||||
(update-in entities [:room :entities] dissoc :candle-aura :candle-flame))
|
||||
|
||||
@@ -799,19 +799,42 @@ void main()
|
||||
:object nil}))
|
||||
entities))
|
||||
|
||||
(defn play-key-sounds [entities]
|
||||
(doseq [[target {:keys [previous-frame-index current-frame-index anim-sound-frames anim x y] :as e}] (get-in entities [:room :entities])]
|
||||
(when (and (not= previous-frame-index current-frame-index)
|
||||
((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)
|
||||
(* (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))))))
|
||||
(defn play-sound-if-necessary [screen entities target {:keys [previous-frame-index current-frame-index anim-sound-frames anim x y] :as e}]
|
||||
(if (and (not= previous-frame-index current-frame-index)
|
||||
((set (keys anim-sound-frames)) anim))
|
||||
(if-let [[snd vol-scale] (get-in anim-sound-frames [anim current-frame-index])]
|
||||
(utils/play-sound! screen entities
|
||||
(or (snd e) (snd (:sounds entities)))
|
||||
target
|
||||
vol-scale
|
||||
[x y])
|
||||
entities)
|
||||
entities))
|
||||
|
||||
(defn play-key-sounds [screen entities]
|
||||
(if (= (get-in entities [:fade :opacity]) 0.0)
|
||||
(loop [entities entities
|
||||
[[target e] & rest] (seq (get-in entities [:room :entities]))]
|
||||
(if e
|
||||
(recur (play-sound-if-necessary screen entities target e) rest)
|
||||
entities))
|
||||
entities))
|
||||
|
||||
(defn update-current-sound-vols! [entities]
|
||||
(loop [entities entities
|
||||
[{:keys [id sound duration loc vol-scale target loc]} & rest] (get-in entities [:current-sounds :value])]
|
||||
(if id
|
||||
(do
|
||||
(sound! sound :set-volume id (utils/get-sound-volume entities target vol-scale loc))
|
||||
(recur entities rest))
|
||||
entities)))
|
||||
|
||||
(defn remove-ended-sounds [screen entities]
|
||||
(update-in entities [:current-sounds :value]
|
||||
(fn [sounds]
|
||||
(filter #(or (= :loop (:type %))
|
||||
(> (:ends-at %) (:total-time screen)))
|
||||
sounds))))
|
||||
|
||||
(defn update-from-room [screen entities]
|
||||
(if-let [update-fn (get-in entities [:room :update-fn])]
|
||||
@@ -924,6 +947,8 @@ void main()
|
||||
:cam {:zoom 0.95
|
||||
:paused? false
|
||||
:object nil}
|
||||
:current-sounds {:object nil
|
||||
:value []}
|
||||
:musics {:object nil
|
||||
:inside-antique (utils/make-music "music/inside-antique.ogg")
|
||||
:town-1 (utils/make-music "music/town-music-1.ogg")
|
||||
@@ -1061,12 +1086,10 @@ void main()
|
||||
(set! (. camera zoom) (:zoom (:cam entities)))
|
||||
(set! (.. camera position x) (:x (:cam entities) 160.0))
|
||||
(set! (.. camera position y) (:y (:cam entities) 120.0)))
|
||||
(let [entities (utils/update-override screen entities)]
|
||||
|
||||
|
||||
(when (= (get-in entities [:fade :opacity])
|
||||
0.0)
|
||||
(play-key-sounds entities))
|
||||
(let [entities (utils/update-override screen entities)
|
||||
entities (play-key-sounds screen entities)
|
||||
entities (update-current-sound-vols! entities)
|
||||
entities (remove-ended-sounds screen entities)]
|
||||
(doseq [m (vals (get-in entities [:musics]))]
|
||||
(when m
|
||||
(music! m :set-volume (utils/current-music-volume (get-in entities [:volume :value])))))
|
||||
|
||||
@@ -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))))
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
(ns advent.core.desktop-launcher
|
||||
(:require [advent.core :refer :all]
|
||||
#_[clojure.tools.nrepl.server])
|
||||
[clojure.tools.nrepl.server])
|
||||
(:import [com.badlogic.gdx.backends.lwjgl LwjglApplication LwjglApplicationConfiguration]
|
||||
[org.lwjgl.input Keyboard]
|
||||
[com.badlogic.gdx Gdx])
|
||||
(:gen-class))
|
||||
|
||||
#_(defmacro start-nrepl-expr [port]
|
||||
(defmacro start-nrepl-expr [port]
|
||||
`(let [{port# :port} (clojure.tools.nrepl.server/start-server :port ~port)]
|
||||
(doseq [port-file# ["target/repl-port" ".nrepl-port"]]
|
||||
(-> port-file#
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
(defn -main
|
||||
[& [port]]
|
||||
#_(try
|
||||
(try
|
||||
(when port (start-nrepl-expr (Integer/parseInt port)))
|
||||
(catch Exception e))
|
||||
(let [cfg (LwjglApplicationConfiguration.)]
|
||||
|
||||
Reference in New Issue
Block a user