diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 8573ae9d..f0ba18f6 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -160,6 +160,7 @@ :origin-x 9 :origin-y 0 :scaled true + :step-sound (sound "ego/step.ogg") :mouse-in? (fn [entities x y] (let [{entity-x :x entity-y :y region :object scale :scale-x} (get-in entities [:room :entities :ego]) @@ -215,6 +216,11 @@ +(defn get-animation-point [animation total-time] + (loop [time total-time] + (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)))) @@ -284,6 +290,7 @@ (clear!) (let [entities (update-cursor screen entities) entities (update-from-script screen entities) + entities (assoc-in entities [:room :entities :ego :last-frame] (get-in entities [:room :entities :ego :object])) entities (update-in entities [:room :entities] (fn [entities] (into entities (for [[id entity] entities] @@ -296,7 +303,15 @@ (if (:update-fn entity) [id ((:update-fn entity) screen entities entity)] [id entity]))))) + current-frame (get-in entities [:room :entities :ego :object]) + all-entities (concat (vals entities) (get-in entities [:room :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))) (label! (:fps entities) :set-text (str (game :fps))) (render! screen (sort-by :baseline all-entities)) entities))