animations in all directions.

This commit is contained in:
2014-09-18 18:14:17 -07:00
parent 0ae2c5cea8
commit 5db858aae5
2 changed files with 40 additions and 23 deletions

View File

@@ -36,7 +36,8 @@
(defn start-animation [screen entity anim]
(let [new-anim (if (keyword? anim)
(anim entity)
(or (get-in entity [(:facing entity) anim])
(anim entity))
anim)]
(if (and anim (not= new-anim (:anim entity)))
(assoc entity
@@ -96,10 +97,12 @@
entities)
(update-in entities [:background :entities target-id]
#(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)))))))
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
:facing (cond (< delta-x 0) :left
(> delta-x 0) :right
:else (:facing %)))
:walk
))))))
(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])]
@@ -110,10 +113,11 @@
@entities)))
(defn get-text-duration [text]
(* (count (s/split text #" ")) 0.75))
(* (count (s/split text #" ")) 0.5))
(defn talk [entities target-id text]
(let [initial-time (atom nil)]
(defn talk [entities target-id text & {:keys [stop?]}]
(let [initial-time (atom nil)
stop? (if (nil? stop?) true stop?)]
(run-action entities
(begin [this screen entities]
(let [_ (swap! initial-time #(or % (:total-time screen)))
@@ -136,7 +140,9 @@
(terminate [this screen entities]
(run! dialogue/talking-screen :stop-talk :target-id target-id)
(stop screen entities target-id)))))
(if stop?
(stop screen entities target-id)
entities)))))
(defn give [entities target-id item]
(run-action entities