animations don't start in the middle.

This commit is contained in:
2014-09-18 17:14:59 -07:00
parent 40a4e54c80
commit 875c9a6af8
2 changed files with 25 additions and 14 deletions

View File

@@ -34,11 +34,18 @@
(assoc entity :scale-x (scale-fn y) :scale-y (scale-fn y))
entity)))
(defn start-animation [screen entity anim]
(let [new-anim (if (keyword? anim)
(anim entity)
anim)]
(if (and anim (not= new-anim (:anim entity)))
(assoc entity
:anim new-anim
:anim-start (:total-time screen))
entity)))
(defn stop [screen entities target-id]
(update-in entities [:background :entities target-id] #(merge %
{:anim nil}
(when (:anim %)
(texture (animation! (:anim %) :get-key-frame 0.25))))))
(update-in entities [:background :entities target-id] #(start-animation screen % :stand)))
(defn dist [x1 y1 x2 y2]
@@ -88,10 +95,11 @@
(do (swap! targets-left rest)
entities)
(update-in entities [:background :entities target-id]
#(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
:anim (cond (< delta-x 0) left
(> delta-x 0) right
:else (:anim %))))))))
#(start-animation screen
(jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
(cond (< delta-x 0) :left
(> delta-x 0) :right
:else nil)))))))
(done? [this screen entities]
(let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:background :entities target-id])]
@@ -117,7 +125,7 @@
:x (get-in entities [:background :entities target-id :x]) :y (+ (get-in entities [:background :entities target-id :y]) height)
:target-id target-id
:scale scale)
(assoc-in entities [:background :entities target-id :anim] (get-in entities [:background :entities target-id :talk]))))
(update-in entities [:background :entities target-id ] #(start-animation screen % :talk))))
(continue [this screen entities] entities)