first step in large refactoring to extract rooms.

This commit is contained in:
2014-10-03 20:00:09 -07:00
parent d672c7ab39
commit 098891dd42
9 changed files with 433 additions and 375 deletions

View File

@@ -30,7 +30,7 @@
(defn jump-to [screen entities entity [x y]]
(let [scale-fn (-> entities :background :scale-fn)
(let [scale-fn (-> entities :room :scale-fn)
entity (assoc entity :x x
:y y
:baseline (- 240 y))]
@@ -50,7 +50,7 @@
entity)))
(defn stop [screen entities target-id]
(update-in entities [:background :entities target-id] #(start-animation screen % :stand)))
(update-in entities [:room :entities target-id] #(start-animation screen % :stand)))
(defn dist [x1 y1 x2 y2]
@@ -68,7 +68,7 @@
(reset! ~entities (<!! c#)))))
(defn walk-straight-to [entities target-id [final-x final-y]]
(let [{start-x :x start-y :y} (get-in @entities [:background :entities target-id])
(let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id])
final-x (int final-x)
final-y (int final-y)]
(run-action entities
@@ -76,7 +76,7 @@
entities)
(continue [this screen entities]
(let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:background :entities target-id])]
(let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])]
(let [delta-x (- final-x from-x)
delta-y (- final-y from-y)
distance (dist from-x from-y final-x final-y)
@@ -89,9 +89,9 @@
(* speed (/ delta-y distance)))]
(if (< distance speed)
(-> entities
(assoc-in [:background :entities target-id :x] final-x)
(assoc-in [:background :entities target-id :y] final-y))
(update-in entities [:background :entities target-id]
(assoc-in [:room :entities target-id :x] final-x)
(assoc-in [:room :entities target-id :y] final-y))
(update-in entities [:room :entities target-id]
#(start-animation screen
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
:facing (cond (< delta-x 0) :left
@@ -101,7 +101,7 @@
))))))
(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])]
(let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:room :entities target-id])]
(< (dist final-x final-y from-x from-y) 1)))
(terminate [this screen entities]
@@ -110,11 +110,11 @@
false))))
(defn walk-to [entities target-id [final-x final-y] & [can-skip?]]
(let [{start-x :x start-y :y} (get-in @entities [:background :entities target-id])
(let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id])
final-x (int final-x)
final-y (int final-y)
path (vec (take-nth 5 (advent.pathfind/visit-all
(:collision (:background @entities))
(:collision (:room @entities))
[(int start-x) (int start-y)]
[final-x final-y])))
path (if (seq path)
@@ -127,7 +127,7 @@
entities)
(continue [this screen entities]
(let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:background :entities target-id])
(let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])
[[target-x target-y] remainder] @targets-left]
(let [delta-x (- target-x from-x)
delta-y (- target-y from-y)
@@ -142,9 +142,9 @@
(if (< distance speed)
(do (swap! targets-left rest)
(-> entities
(assoc-in [:background :entities target-id :x] target-x)
(assoc-in [:background :entities target-id :y] target-y)))
(update-in entities [:background :entities target-id]
(assoc-in [:room :entities target-id :x] target-x)
(assoc-in [:room :entities target-id :y] target-y)))
(update-in entities [:room :entities target-id]
#(start-animation screen
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
:facing (cond (< delta-x 0) :left
@@ -154,7 +154,7 @@
))))))
(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])]
(let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:room :entities target-id])]
(< (dist final-x final-y from-x from-y) 1)))
(terminate [this screen entities]
@@ -172,15 +172,15 @@
(run-action entities
(begin [this screen entities]
(let [_ (swap! initial-time #(or % (:total-time screen)))
target-y (get-in entities [:background :entities target-id :y])
scale-fn (get-in entities [:background :scale-fn])
target-y (get-in entities [:room :entities target-id :y])
scale-fn (get-in entities [:room :scale-fn])
scale (scale-fn target-y)
height (* scale 36)]
(run! dialogue/talking-screen :on-talk :text text
:x (get-in entities [:background :entities target-id :x]) :y (+ (get-in entities [:background :entities target-id :y]) height)
:x (get-in entities [:room :entities target-id :x]) :y (+ (get-in entities [:room :entities target-id :y]) height)
:target-id target-id
:scale scale)
(update-in entities [:background :entities target-id ] #(start-animation screen % :talk))))
(update-in entities [:room :entities target-id ] #(start-animation screen % :talk))))
(continue [this screen entities] entities)
@@ -298,12 +298,12 @@
false))
(run-action entities
(begin [this screen entities]
(let [ego (get-in entities [:background :entities :ego])
(let [ego (get-in entities [:room :entities :ego])
entities (-> entities
(assoc-in [:background] (get-in entities [:backgrounds new-background]))
(assoc-in [:background :entities :ego] ego))]
(assoc-in [:room] (get-in entities [:rooms new-background]))
(assoc-in [:room :entities :ego] ego))]
(-> entities
(update-in [:background :entities :ego] #(jump-to screen entities % [x y])))))
(update-in [:room :entities :ego] #(jump-to screen entities % [x y])))))
(continue [this screen entities]
(update-in entities [:transition :opacity] - 0.075))
@@ -316,3 +316,14 @@
(can-skip? [this screen entities]
false)))
(defn do-dialogue [entities & pairs]
(loop [pairs (partition 2 pairs)]
(let [[[target line]] pairs
result (actions/talk entities target line)]
(if (seq (rest pairs))
(recur (rest pairs))
result))))
(defn respond [entities line & more]
(apply do-dialogue entities :ego line more))