moving ego into background.

This commit is contained in:
2014-09-18 16:29:33 -07:00
parent e889a2ad41
commit 7d8ba284d7
3 changed files with 44 additions and 26 deletions

View File

@@ -35,10 +35,10 @@
entity)))
(defn stop [screen entities target-id]
(update-in entities [target-id] #(merge %
{:anim nil}
(when (:anim %)
(texture (animation! (:anim %) :get-key-frame 0.25))))))
(update-in entities [:background :entities target-id] #(merge %
{:anim nil}
(when (:anim %)
(texture (animation! (:anim %) :get-key-frame 0.25))))))
(defn dist [x1 y1 x2 y2]
@@ -56,7 +56,7 @@
(reset! ~entities (<!! c#)))))
(defn walk-to [entities target-id [final-x final-y]]
(let [{start-x :x start-y :y} (@entities target-id)
(let [{start-x :x start-y :y} (get-in @entities [:background :entities target-id])
final-x (int final-x)
final-y (int final-y)
path (vec (take-nth 5 (advent.pathfind/visit-all
@@ -73,7 +73,7 @@
entities)
(continue [this screen entities]
(let [{from-x :x from-y :y :keys [left right] :as target-entity} (entities target-id)
(let [{from-x :x from-y :y :keys [left right] :as target-entity} (get-in entities [:background :entities target-id])
[[target-x target-y] remainder] @targets-left]
(let [delta-x (- target-x from-x)
delta-y (- target-y from-y)
@@ -87,14 +87,14 @@
(if (< distance 1)
(do (swap! targets-left rest)
entities)
(update-in entities [target-id]
(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 %))))))))
(done? [this screen entities]
(let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (entities target-id)]
(let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:background :entities target-id])]
(< (dist final-x final-y from-x from-y) 1)))
(terminate [this screen entities]
@@ -109,15 +109,15 @@
(run-action entities
(begin [this screen entities]
(let [_ (swap! initial-time #(or % (:total-time screen)))
target-y (get-in entities [target-id :y])
target-y (get-in entities [:background :entities target-id :y])
scale-fn (get-in entities [:background :scale-fn])
scale (scale-fn target-y)
height (* scale 36)]
(run! dialogue/talking-screen :on-talk :text text
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) height)
: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 [target-id :anim] (get-in entities [target-id :talk]))))
(assoc-in entities [:background :entities target-id :anim] (get-in entities [:background :entities target-id :talk]))))
(continue [this screen entities] entities)
@@ -136,7 +136,7 @@
(sound! (sound "pickup.mp3") :play)
(-> entities
(update-in [target-id :inventory] #(conj % item))
(update-in [:background :entities target-id :inventory] #(conj % item))
(assoc-in [:cursor :current] item)))
(continue [this screen entities] entities)
@@ -168,10 +168,12 @@
entities))
(run-action entities
(begin [this screen entities]
(-> entities
(assoc-in [:background] (get-in entities [:backgrounds new-background]))
(assoc-in [:ego :x] x)
(assoc-in [:ego :y] y)))
(let [ego (get-in entities [:background :entities :ego])]
(-> entities
(assoc-in [:background] (get-in entities [:backgrounds new-background]))
(assoc-in [:background :entities :ego] ego)
(assoc-in [:background :entities :ego :x] x)
(assoc-in [:background :entities :ego :y] y))))
(continue [this screen entities]
(update-in entities [:transition :opacity] - 0.075))