From 57a84f5101aad5d97172ddaf8faca2d9ab42f967 Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Mon, 3 Nov 2014 22:51:08 -0800 Subject: [PATCH] added concept of different background musics. --- desktop/src-common/advent/actions.clj | 10 +++++++++- .../src-common/advent/screens/rooms/behind_house.clj | 3 ++- desktop/src-common/advent/screens/rooms/cat_tree.clj | 3 ++- .../advent/screens/rooms/inside_castle.clj | 3 ++- .../src-common/advent/screens/rooms/inside_house.clj | 3 ++- .../advent/screens/rooms/outside_castle.clj | 3 ++- .../advent/screens/rooms/outside_house.clj | 3 ++- desktop/src-common/advent/screens/scene.clj | 12 +++++++++--- 8 files changed, 30 insertions(+), 10 deletions(-) diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 5a216c9e..66df5590 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -360,9 +360,17 @@ (run-action entities (begin [this screen entities] (let [ego (get-in entities [:room :entities :ego]) + old-music (get-in entities [:room :music]) entities (-> entities (assoc-in [:room] (get-in entities [:rooms new-background])) - (assoc-in [:room :entities :ego] ego))] + (assoc-in [:room :entities :ego] ego)) + new-music (get-in entities [:room :music])] + (when (not= new-music old-music) + (doseq [[k v] (:musics entities) + :when (and v (not= new-music k))] + (sound! v :stop)) + (when new-music + (sound! (get-in entities [:musics new-music]) :loop 0.30))) (-> entities (update-in [:room :entities :ego] #(jump-to screen entities % [x y]))))) diff --git a/desktop/src-common/advent/screens/rooms/behind_house.clj b/desktop/src-common/advent/screens/rooms/behind_house.clj index 812e86b5..9276c03f 100644 --- a/desktop/src-common/advent/screens/rooms/behind_house.clj +++ b/desktop/src-common/advent/screens/rooms/behind_house.clj @@ -10,7 +10,8 @@ [play-clj.g2d :refer :all])) (defn make [screen] - (rooms/make :interactions + (rooms/make :music :town-2 + :interactions {:left-dir {:box [0 131 20 224] :script (actions/get-script entities diff --git a/desktop/src-common/advent/screens/rooms/cat_tree.clj b/desktop/src-common/advent/screens/rooms/cat_tree.clj index c383ac2c..d8b7360f 100644 --- a/desktop/src-common/advent/screens/rooms/cat_tree.clj +++ b/desktop/src-common/advent/screens/rooms/cat_tree.clj @@ -12,7 +12,8 @@ (let [cat-stand-sheet (texture! (texture "cat-tree/cat-stand.png") :split 22 10) cat-stand (animation 0.15 (for [i (flatten [(repeat 10 0) 1 1 (repeat 10 0) 2 3 4 3 0 0 2 3 4 3 (repeat 10 0) 1 1 (repeat 10 0) 5 5 6 6 7 (repeat 10 [7 8]) 6 5 0])] (aget cat-stand-sheet 0 i)))] - (rooms/make :interactions + (rooms/make :music :town-2 + :interactions {:down-dir {:box [150 0 270 20] :script (actions/get-script entities (actions/walk-to entities :ego [203 1]) diff --git a/desktop/src-common/advent/screens/rooms/inside_castle.clj b/desktop/src-common/advent/screens/rooms/inside_castle.clj index 440a68b1..04ce1a76 100644 --- a/desktop/src-common/advent/screens/rooms/inside_castle.clj +++ b/desktop/src-common/advent/screens/rooms/inside_castle.clj @@ -92,7 +92,8 @@ (let [game-player-talk-sheet (texture! (texture "inside-castle/game-player-talk.png") :split 40 44) game-player-talk (animation 0.15 (for [i [0 2 0 2 0 2 0 3 0 2 0 1 0 0 0 0 2 0 2 0 3 0 1 0 1 0 0 1 0 2 0 3 0]] (aget game-player-talk-sheet 0 i)))] - (rooms/make :interactions + (rooms/make :music :town-1 + :interactions {:right-door {:box [286 140 306 160] :cursor :right :script (actions/get-script entities diff --git a/desktop/src-common/advent/screens/rooms/inside_house.clj b/desktop/src-common/advent/screens/rooms/inside_house.clj index a4a43849..4d66c2cb 100644 --- a/desktop/src-common/advent/screens/rooms/inside_house.clj +++ b/desktop/src-common/advent/screens/rooms/inside_house.clj @@ -15,7 +15,8 @@ (aget wizard-sheet 0 i))) wizard-talk (animation 0.2 (for [i [0 2 0 2 1 2 0 3 0 2 0 1 0 2]] (aget wizard-sheet 0 i)))] - (rooms/make :interactions {:down-dir {:box [151 0 320 20] + (rooms/make :music :inside-fangald + :interactions {:down-dir {:box [151 0 320 20] :script (actions/get-script entities (actions/walk-to entities :ego [237 1]) (actions/transition-background entities :outside-house [262 88])) diff --git a/desktop/src-common/advent/screens/rooms/outside_castle.clj b/desktop/src-common/advent/screens/rooms/outside_castle.clj index 7616bdbb..da7814b4 100644 --- a/desktop/src-common/advent/screens/rooms/outside_castle.clj +++ b/desktop/src-common/advent/screens/rooms/outside_castle.clj @@ -15,7 +15,8 @@ (aget peddler-sheet 0 i))) peddler-stand (animation 0.2 (for [i (flatten [(repeat 5 0) 6])] (aget peddler-sheet 0 i)))] - (rooms/make :interactions + (rooms/make :music :town-2 + :interactions {:right-dir {:box [300 40 320 140] :script (actions/get-script entities diff --git a/desktop/src-common/advent/screens/rooms/outside_house.clj b/desktop/src-common/advent/screens/rooms/outside_house.clj index 46df2de5..cfcd06e3 100644 --- a/desktop/src-common/advent/screens/rooms/outside_house.clj +++ b/desktop/src-common/advent/screens/rooms/outside_house.clj @@ -118,7 +118,8 @@ (aget sheep-stand-sheet 0 i))) sheep-walk (animation 0.05 (for [i (range 6)] (aget sheep-walk-sheet 0 i)))] - (rooms/make :interactions + (rooms/make :music :town-2 + :interactions {:door {:box [258 100 281 160] :script (actions/get-script entities diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 39b8f9d0..c2301119 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -153,13 +153,15 @@ (defn animate [entity screen] (merge entity (animation->texture (update-in screen [:total-time] #(- % (:anim-start entity))) (:anim entity)))) + +(defn play-sound [snd] + (sound! snd :loop 0.3)) + (defscreen scene :on-show (fn [screen entities] (update! screen :renderer (stage) :camera (orthographic)) - (let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0) - music (sound "town-music.mp3") - _ (sound! music :loop 0.30) + (let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0) rooms {:inside-house (rooms.inside-house/make screen) :outside-house (rooms.outside-house/make screen) :behind-house (rooms.behind-house/make screen) @@ -167,6 +169,10 @@ :inside-castle (rooms.inside-castle/make screen) :outside-castle (rooms.outside-castle/make screen)}] {:rooms rooms + :musics {:object nil + :town-1 (sound "town-music.mp3") + :town-2 (doto (sound "town-music-2.mp3") play-sound) + :inside-fangald (sound "inside-fangald.mp3")} :state {:object nil :active? true :inventory []}