simplifying and extending sounds.
This commit is contained in:
BIN
desktop/resources/scratch.ogg
Normal file
BIN
desktop/resources/scratch.ogg
Normal file
Binary file not shown.
BIN
desktop/resources/scratch.wav
Normal file
BIN
desktop/resources/scratch.wav
Normal file
Binary file not shown.
@@ -295,6 +295,8 @@
|
||||
: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}}
|
||||
:scratch (sound "scratch.ogg")
|
||||
:talk peddler-talk :stand peddler-stand
|
||||
:talk-color (color 1.0 0.9 0.4 1.0)
|
||||
:script (actions/get-script
|
||||
|
||||
@@ -235,6 +235,8 @@
|
||||
:scale-x start-scale
|
||||
:scale-y start-scale
|
||||
:talk-color (color 0.6 1.0 1.0 1.0)
|
||||
|
||||
|
||||
|
||||
:mouse-in? (fn [entities x y]
|
||||
(let [{entity-x :x entity-y :y region :object scale :scale-x} (get-in entities [:room :entities :ego])
|
||||
@@ -277,7 +279,11 @@
|
||||
:walkie-talkie (actions/get-script entities (common/listen-to-frankie entities))
|
||||
nil))
|
||||
:x (first start-pos) :y (last start-pos)
|
||||
:id "ego"}]
|
||||
:id "ego"}
|
||||
ego (assoc ego :anim-sound-frames {(get-in ego [:left :walk]) {2 :step-sound
|
||||
6 :step-sound}
|
||||
(get-in ego [:right :walk]) {2 :step-sound
|
||||
6 :step-sound}})]
|
||||
(actions/start-animation screen
|
||||
(merge (animation->texture screen (:stand (:right ego))) ego)
|
||||
:stand)))
|
||||
@@ -317,9 +323,12 @@
|
||||
(if (> (- time (animation! animation :get-animation-duration)) 0)
|
||||
(recur (- time (animation! animation :get-animation-duration)))
|
||||
time)))
|
||||
|
||||
(defn animate [entity screen]
|
||||
(merge entity (animation->texture (update-in screen [:total-time] #(- % (:anim-start entity)))
|
||||
(:anim entity))))
|
||||
(:anim entity))
|
||||
{:current-frame-index (texture! (:anim entity) :get-key-frame-index (get-animation-point (:anim entity) (- (:total-time screen) (:anim-start entity))))
|
||||
:previous-frame-index (texture! (:anim entity) :get-key-frame-index (get-animation-point (:anim entity) (- (:total-time screen) (:anim-start entity) (or (:delta-time screen) 0))))}))
|
||||
|
||||
|
||||
(defn get-layers [entities]
|
||||
@@ -341,6 +350,15 @@
|
||||
:mints-eaten 0
|
||||
:seen-intro? false}))
|
||||
|
||||
(defn play-key-sounds [entities]
|
||||
(doseq [{:keys [previous-frame-index current-frame-index anim-sound-frames anim] :as e} (vals 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))))))
|
||||
|
||||
|
||||
|
||||
(defscreen scene
|
||||
:on-timer
|
||||
(fn [screen [entities]]
|
||||
@@ -426,22 +444,18 @@
|
||||
(if (:anim entity)
|
||||
[id (animate entity screen)]
|
||||
[id entity])))))
|
||||
entities (update-in entities [:room :entities] (fn [entities]
|
||||
(into entities
|
||||
(for [[id entity] entities]
|
||||
(if (:update-fn entity)
|
||||
[id ((:update-fn entity) screen entities entity)]
|
||||
[id entity])))))
|
||||
current-frame (get-in entities [:room :entities :ego :object])
|
||||
entities (update-in entities [:room :entities] (fn [entities]
|
||||
(into entities
|
||||
(for [[id entity] entities]
|
||||
(if (:update-fn entity)
|
||||
[id ((:update-fn entity) screen entities entity)]
|
||||
[id entity])))))
|
||||
|
||||
layers (get-layers entities)
|
||||
|
||||
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
|
||||
(when (and (not= current-frame (get-in entities [:room :entities :ego :last-frame]))
|
||||
(or (= (get-in entities [:room :entities :ego :anim]) (get-in entities [:room :entities :ego :left :walk]))
|
||||
(= (get-in entities [:room :entities :ego :anim]) (get-in entities [:room :entities :ego :right :walk])))
|
||||
(#{2 6}
|
||||
(texture! (get-in entities [:room :entities :ego :anim]) :get-key-frame-index (get-animation-point (get-in entities [:room :entities :ego :anim]) (- (:total-time screen) (get-in entities [:room :entities :ego :anim-start]))))))
|
||||
(sound! (get-in entities [:room :entities :ego :step-sound]) :play (* (/ (get-in entities [:room :entities :ego :scale-x]) 1.5) 0.75)))
|
||||
(play-key-sounds (get-in entities [:room :entities]))
|
||||
|
||||
(label! (:fps entities) :set-text (str (game :fps)))
|
||||
(render! screen (sort-by :baseline all-entities))
|
||||
#_(render! screen [(:fps entities)])
|
||||
|
||||
Reference in New Issue
Block a user