animations don't start in the middle.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -59,12 +59,15 @@
|
||||
(defn get-ego [screen]
|
||||
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
||||
talk-sheet (texture! (texture "ego/talk.png") :split 16 36)
|
||||
stand-sheet (texture! (texture "ego/stand.png") :split 18 36)
|
||||
ego {:right (animation 0.075 (for [i (range 8)]
|
||||
(texture (aget player-sheet 0 i))))
|
||||
:left (animation 0.075 (for [i (range 8)]
|
||||
(texture (aget player-sheet 1 i))))
|
||||
:talk (animation 0.2 (for [i (range 8)]
|
||||
(texture (aget talk-sheet 0 i))))
|
||||
:stand (animation 0.1 (for [i (flatten [(repeat 6 [(repeat 10 0) (repeat 3 1) (repeat 20 0)]) 3 4 5 5 5 6 5 6 5 6 5 4 3 ])]
|
||||
(texture (aget stand-sheet 0 i))))
|
||||
|
||||
:baseline 95
|
||||
:origin-x 9
|
||||
@@ -165,7 +168,9 @@
|
||||
(assoc (texture "house.png") :x 0 :y 0 :baseline 122)
|
||||
(assoc (texture "overdirt.png") :x 0 :y 0 :baseline 240)
|
||||
(assoc (texture "background-trees.png") :x 0 :y 0 :baseline 44)]
|
||||
:entities {:sheep (assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep)}
|
||||
:entities {:sheep (actions/start-animation screen
|
||||
(assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160)
|
||||
sheep)}
|
||||
:collision "outsidehouse/collision.png"
|
||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
|
||||
|
||||
@@ -196,10 +201,8 @@
|
||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))}))
|
||||
|
||||
(defn animate [entity screen]
|
||||
(if (:anim entity)
|
||||
(merge entity (animation->texture screen (:anim entity)))
|
||||
entity)
|
||||
)
|
||||
(merge entity (animation->texture (update-in screen [:total-time] #(- % (:anim-start entity)))
|
||||
(:anim entity))))
|
||||
(defscreen scene
|
||||
:on-show
|
||||
(fn [screen entities]
|
||||
|
||||
Reference in New Issue
Block a user