totally reworking music transitions.
This commit is contained in:
@@ -464,30 +464,29 @@
|
||||
music
|
||||
(time music)))
|
||||
|
||||
(defn transition-music
|
||||
([entities new-music]
|
||||
(transition-music entities (get-music (get-in @entities [:room :music]) (get-in @entities [:state :time])) new-music))
|
||||
([entities old-music new-music]
|
||||
(let [current-volume (atom 1.0)]
|
||||
(run-action entities
|
||||
(begin [this screen entities]
|
||||
(defn transition-music [entities new-music]
|
||||
(let [current-volume (atom 1.0)]
|
||||
(run-action entities
|
||||
(begin [this screen entities]
|
||||
(assoc-in entities [:tweens :fade-out-music] (utils/tween :fade-out-music screen [:volume :value] 1.0 0.0 2.0)))
|
||||
|
||||
(continue [this screen entities]
|
||||
entities)
|
||||
|
||||
(continue [this screen entities]
|
||||
(let [new-volume (swap! current-volume #(- % 0.01))]
|
||||
(music! (get-in entities [:musics old-music]) :set-volume new-volume))
|
||||
entities)
|
||||
(done? [this screen entities]
|
||||
(nil? (get-in entities [:tweens :fade-out-music])))
|
||||
|
||||
(done? [this screen entities]
|
||||
(>= 0.1 @current-volume))
|
||||
(terminate [this screen entities]
|
||||
(music! (utils/get-current-music entities) :stop)
|
||||
(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) :play)
|
||||
entities))
|
||||
|
||||
(terminate [this screen entities]
|
||||
(music! (get-in entities [:musics old-music]) :stop)
|
||||
(music! (get-in entities [:musics new-music]) :set-volume 1.0)
|
||||
(music! (get-in entities [:musics new-music]) :play)
|
||||
entities)
|
||||
(can-skip? [this screen entities]
|
||||
false)))))
|
||||
(can-skip? [this screen entities]
|
||||
false))))
|
||||
|
||||
|
||||
(defn transition-background [entities new-background [x y]]
|
||||
@@ -498,9 +497,12 @@
|
||||
(begin [this screen entities]
|
||||
(doseq [[k] (get-in entities [:room :timers])]
|
||||
(remove-timer! screen k))
|
||||
(-> entities
|
||||
(assoc-in [:tweens :fade-out] (utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 0.5))
|
||||
(assoc-in [:cursor :current] :main)))
|
||||
(as-> entities e
|
||||
(assoc-in e [:tweens :fade-out] (utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 0.5))
|
||||
(if music-changed?
|
||||
(assoc-in e [:tweens :fade-out-music] (utils/tween :fade-out-music screen [:volume :value] 1.0 0.0 0.5))
|
||||
e)
|
||||
(assoc-in e [:cursor :current] :main)))
|
||||
|
||||
(continue [this screen entities]
|
||||
(when music-changed?
|
||||
@@ -510,8 +512,7 @@
|
||||
(done? [this screen entities]
|
||||
(>= (get-in entities [:fade :opacity]) 1.0))
|
||||
|
||||
(terminate [this screen entities]
|
||||
(println "done")
|
||||
(terminate [this screen entities]
|
||||
(if-let [next-time (get-in entities [:state :next-time])]
|
||||
(-> entities
|
||||
(assoc-in [:state :time] next-time)
|
||||
@@ -523,11 +524,14 @@
|
||||
(begin [this screen entities]
|
||||
(let [ego (get-in entities [:room :entities :ego])
|
||||
old-music (get-music (get-in entities [:room :music]) (get-in entities [:state :time]))
|
||||
entities (-> entities
|
||||
(assoc-in [:room] (get-in entities [:rooms new-background]))
|
||||
(assoc-in [:room :entities :ego] ego)
|
||||
(assoc-in [:state :last-room] new-background)
|
||||
(assoc-in [:tweens :fade-in] (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 0.5)))
|
||||
entities (as-> entities e
|
||||
(assoc-in e [:room] (get-in entities [:rooms new-background]))
|
||||
(assoc-in e [:room :entities :ego] ego)
|
||||
(assoc-in e [:state :last-room] new-background)
|
||||
(assoc-in e [:tweens :fade-in] (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 0.5))
|
||||
(if music-changed?
|
||||
(assoc-in e [:tweens :fade-in-music] (utils/tween :fade-in-music screen [:volume :value] 0.0 1.0 0.5))
|
||||
e))
|
||||
new-music (get-music (get-in entities [:room :music]) (get-in entities [:state :time]))
|
||||
apply-state (get-in entities [:room :apply-state])
|
||||
entities (if apply-state
|
||||
@@ -545,8 +549,6 @@
|
||||
(update-in [:room :entities :ego] #(jump-to screen entities % [x y] true)))))
|
||||
|
||||
(continue [this screen entities]
|
||||
(when music-changed?
|
||||
(music! (get-in entities [:musics new-music]) :set-volume (max (- 1.0 (get-in entities [:fade :opacity])) 0.0)))
|
||||
entities)
|
||||
|
||||
(done? [this screen entities]
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
:baseline 1000))
|
||||
|
||||
(defn play-battle [entities anim]
|
||||
(actions/transition-music entities :town-1 :fight)
|
||||
(actions/transition-music entities :fight)
|
||||
(actions/add-entity entities :fight (get-in @entities [:room :fight]))
|
||||
(actions/add-entity entities :hands-fight (get-in @entities [:room :hands-fight]))
|
||||
(actions/play-animation entities :hands-fight anim)
|
||||
(actions/transition-music entities :fight :town-1)
|
||||
(actions/transition-music entities nil)
|
||||
(actions/remove-entity entities :hands-fight)
|
||||
(actions/remove-entity entities :fight))
|
||||
|
||||
|
||||
@@ -100,11 +100,11 @@
|
||||
(actions/transition-background entities :space [0 65])
|
||||
(actions/walk-straight-to entities :ego [140 55] :face :right)
|
||||
(actions/play-animation entities :blergh :appear :stop? false)
|
||||
(actions/transition-music entities :town-1 :fight))
|
||||
(actions/transition-music entities :fight))
|
||||
|
||||
(defn pull-sword [entities]
|
||||
(actions/play-animation entities :ego :reach)
|
||||
(actions/transition-music entities :town-1 :pull-sword)
|
||||
(actions/transition-music entities :pull-sword)
|
||||
(actions/add-entity entities :blackout (get-in @entities [:room :blackout]))
|
||||
(actions/add-entity entities :pull-sword (get-in @entities [:room :pull-sword]))
|
||||
(actions/play-animation entities :pull-sword :pull-sword)
|
||||
@@ -112,7 +112,7 @@
|
||||
(actions/remove-entity entities :sword)
|
||||
(actions/remove-entity entities :pull-sword)
|
||||
(actions/remove-entity entities :blackout)
|
||||
(actions/transition-music entities :pull-sword :town-1)
|
||||
(actions/transition-music entities nil)
|
||||
(actions/do-dialogue entities :ego "That was weird."
|
||||
:ego "I have to go show my friends!")
|
||||
|
||||
|
||||
@@ -60,9 +60,14 @@
|
||||
|
||||
(defn left-click [screen entities]
|
||||
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
|
||||
(println "clicked " [x y])
|
||||
(if ((:mouse-in? (:inventory entities)) x y)
|
||||
(cond
|
||||
((:mouse-in? (:inventory entities)) x y)
|
||||
(click-inventory screen entities)
|
||||
(utils/intersects? (:close entities) [x y])
|
||||
(assoc-in entities [:tweens :fade-out] (utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish #(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen))
|
||||
%)))
|
||||
|
||||
:else
|
||||
(let [interaction (first (filter #((:mouse-in? %) entities x y)
|
||||
(get-in entities [:room :interactions])))
|
||||
interacting-entity (first (sort-by (comp - :baseline) (filter #(and (:mouse-in? %)
|
||||
@@ -358,7 +363,6 @@
|
||||
(sound! (snd e) :play (* (/ (get-in entities [:ego :scale-x]) 1.5) 0.75))))))
|
||||
|
||||
|
||||
|
||||
(defscreen scene
|
||||
:on-timer
|
||||
(fn [screen [entities]]
|
||||
@@ -406,6 +410,10 @@
|
||||
:started? false}
|
||||
:volume {:object nil
|
||||
:value 0.0}
|
||||
:music-override {:object nil
|
||||
:value nil}
|
||||
:close (assoc (texture "close.png") :x 304 :y 224 :width 16 :height 16 :baseline 9000)
|
||||
|
||||
:cursor {:id "cursor"
|
||||
:current :main
|
||||
:last :main
|
||||
@@ -419,6 +427,7 @@
|
||||
:inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000
|
||||
:mouse-in? (zone/box 278 0 320 42))
|
||||
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 0)}]
|
||||
(music! (utils/get-current-music entities) :set-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]))]))
|
||||
|
||||
@@ -455,6 +464,8 @@
|
||||
|
||||
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
|
||||
(play-key-sounds (get-in entities [:room :entities]))
|
||||
(when-let [current-music (utils/get-current-music entities)]
|
||||
(music! current-music :set-volume (get-in entities [:volume :value]) ))
|
||||
|
||||
(label! (:fps entities) :set-text (str (game :fps)))
|
||||
(render! screen (sort-by :baseline all-entities))
|
||||
|
||||
@@ -150,3 +150,12 @@
|
||||
(and (:object e)
|
||||
(< (:x e) x (+ (:x e) (or (:width e) (.getWidth (:object e)))))
|
||||
(< (:y e) y (+ (:y e) (or (:height e) (.getHeight (:object e)))))))
|
||||
|
||||
(defn get-current-music [entities]
|
||||
(let [time (get-in entities [:state :time])
|
||||
musics (:musics entities)
|
||||
override-music (musics (get-in entities [:music-override :value]))
|
||||
current-music (musics (get-in entities [:room :music]))
|
||||
current-time-music (musics (get-in entities [:room :music time]))]
|
||||
(or override-music current-music current-time-music)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user