diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 257767c3..3805d7d9 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -110,7 +110,7 @@ (can-skip? [this screen entities] false)))) -(defn play-animation [entities target-id anim] +(defn play-animation [entities target-id anim & {:keys [stop?]}] (run-action entities (begin [this screen entities] (update-in entities [:room :entities target-id] #(start-animation screen % anim) )) @@ -123,7 +123,9 @@ (- (:total-time screen) (get-in entities [:room :entities target-id :anim-start])))) (terminate [this screen entities] - (stop screen entities target-id)) + (if (or (nil? stop?) stop?) + (stop screen entities target-id) + (assoc-in entities [:room :entities target-id :anim] nil))) (can-skip? [this screen entities] false))) @@ -196,9 +198,10 @@ (defn get-text-duration [text] (* (count (s/split text #" ")) 0.5)) -(defn talk [entities target-id text & {:keys [stop?]}] +(defn talk [entities target-id text & {:keys [stop? animate?]}] (let [initial-time (atom nil) - stop? (if (nil? stop?) true stop?)] + stop? (if (nil? stop?) true stop?) + animate? (if (nil? animate?) true animate?)] (run-action entities (begin [this screen entities] (let [_ (swap! initial-time #(or % (:total-time screen))) @@ -211,7 +214,9 @@ :x (get-in entities [:room :entities target-id :x]) :y (+ (get-in entities [:room :entities target-id :y]) height) :target-id target-id :scale scale) - (update-in entities [:room :entities target-id ] #(start-animation screen % :talk)))) + (if animate? + (update-in entities [:room :entities target-id ] #(start-animation screen % :talk)) + entities))) (continue [this screen entities] entities) @@ -303,6 +308,23 @@ (can-skip? [this screen entities] false))) +(defn play-sound [entities sound-file] + (let [m (music sound-file)] + (run-action entities + (begin [this screen entities] + (music! m :play) + entities) + + (continue [this screen entities] entities) + + (done? [this screen entities] + (not (music! m :is-playing))) + + (terminate [this screen entities] + entities) + (can-skip? [this screen entities] + false)))) + (defn give [entities item] (run-action entities (begin [this screen entities] diff --git a/desktop/src-common/advent/screens/rooms/behind_house.clj b/desktop/src-common/advent/screens/rooms/behind_house.clj index 9276c03f..9c887b75 100644 --- a/desktop/src-common/advent/screens/rooms/behind_house.clj +++ b/desktop/src-common/advent/screens/rooms/behind_house.clj @@ -55,13 +55,12 @@ :script (actions/get-script entities (if (get-in @entities [:state :opened-crack?]) (do (actions/walk-to entities :ego [70 80]) - (actions/play-animation entities :ego :squat) - (actions/talk entities :ego "I can see Gandarf, the wizard inside.") - (actions/play-animation entities :ego :squat) - (actions/talk entities :ego "It looks like he's opening his Magi-safe.") - (actions/play-animation entities :ego :squat) - (actions/talk entities :ego "[todo: sounds play.]") - (actions/play-animation entities :ego :squat) + (actions/play-animation entities :ego :start-squat :stop? false) + (actions/talk entities :ego "I can see Gandarf, the wizard inside." :animate? false :stop? false) + (actions/talk entities :ego "It looks like he's opening his Magi-safe." :animate? false :stop? false) + (actions/play-sound entities "safe-sound.ogg") + (actions/talk entities :ego "So that's the code to his safe..." :animate? false :stop? false) + (actions/play-animation entities :ego :end-squat) (actions/talk entities :ego "A lot of good it'll do me to know his password while he's still there.")) (do (actions/walk-to entities :ego [80 80]) (actions/talk entities :ego "It looks like the wall is crumbling here.") diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 00995fa2..cd6243cb 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -91,6 +91,10 @@ (texture (aget stand-sheet 0 i)))) talk-anim (animation 0.2 (for [i (range 8)] (texture (aget talk-sheet 0 i)))) + start-squat (animation 0.05 (for [i [0 1 2 3]] + (texture (aget squat-sheet 0 i)))) + end-squat (animation 0.05 (for [i [3 2 1 0]] + (texture (aget squat-sheet 0 i)))) squat-anim (animation 0.05 (for [i [0 1 2 3 3 3 3 3 3 3 3 3 3 3 3 2 1] ] (texture (aget squat-sheet 0 i)))) reach-anim (animation 0.1 (for [i [0 1 2 3 3 3 3 3 3 2 1 0]] @@ -107,6 +111,8 @@ :stand stand-anim :talk talk-anim :squat squat-anim + :start-squat start-squat + :end-squat end-squat :reach reach-anim :cat-toy cat-toy-anim [:fire 1] fire-1-anim @@ -115,6 +121,8 @@ :left {:walk (utils/flip walk-right) :stand (utils/flip stand-anim) :talk (utils/flip talk-anim) + :start-squat (utils/flip start-squat) + :end-squat (utils/flip end-squat) :squat (utils/flip squat-anim) :reach (utils/flip reach-anim) :cat-toy (utils/flip cat-toy-anim)