finishing refactor.
This commit is contained in:
@@ -40,26 +40,26 @@
|
|||||||
(assoc entity :scale-x (scale-fn y) :scale-y (scale-fn y))
|
(assoc entity :scale-x (scale-fn y) :scale-y (scale-fn y))
|
||||||
entity)))
|
entity)))
|
||||||
|
|
||||||
(defn walk-to-fn [[x y] target-id]
|
(defn walk-to-fn [[target-x target-y] target-id]
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
(let [{:keys [left right anim] :as target-entity} (entities target-id)
|
(let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (entities target-id)]
|
||||||
target-loc {:x x :y y}]
|
(let [delta-x (- target-x from-x)
|
||||||
(let [delta-x (- x (:x target-entity))
|
delta-y (- target-y from-y)
|
||||||
delta-y (- y (:y target-entity))
|
|
||||||
mag (Math/sqrt (+ (* delta-x delta-x) (* delta-y delta-y)))
|
mag (Math/sqrt (+ (* delta-x delta-x) (* delta-y delta-y)))
|
||||||
vector-x (* 1.5 (/ delta-x mag))
|
moved-x (* 1.5 (/ delta-x mag))
|
||||||
vector-y (* 1.5 (/ delta-y mag))]
|
moved-y (* 1.5 (/ delta-y mag))]
|
||||||
(if (< mag 1)
|
(if (< mag 1)
|
||||||
(assoc entities target-id (assoc target-entity :actions (rest (:actions target-entity)) :anim nil))
|
(assoc entities target-id (assoc target-entity :actions (rest (:actions target-entity)) :anim nil))
|
||||||
(assoc entities target-id
|
(assoc entities target-id
|
||||||
(assoc (move-to screen entities target-entity [(+ vector-x (:x target-entity)) (+ vector-y (:y target-entity))])
|
(assoc (move-to screen entities target-entity [(+ moved-x from-x) (+ moved-y from-y)])
|
||||||
:anim (if (< vector-x 0) left right))))))))
|
:anim (if (< moved-x 0) left right))))))))
|
||||||
|
|
||||||
(defn stop-fn [target-id]
|
(defn stop-fn [target-id]
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
(let [target (target-id entities)]
|
(let [target (target-id entities)]
|
||||||
(assoc-in entities [target-id] (merge target
|
(assoc-in entities [target-id] (merge target
|
||||||
{:anim nil}
|
{:anim nil
|
||||||
|
:actions (rest (:actions target))}
|
||||||
(when (:anim target)
|
(when (:anim target)
|
||||||
(texture (animation! (:anim target) :get-key-frame 0.25))))))))
|
(texture (animation! (:anim target) :get-key-frame 0.25))))))))
|
||||||
|
|
||||||
@@ -68,11 +68,12 @@
|
|||||||
path (vec (take-nth 2 (advent.pathfind/visit-all
|
path (vec (take-nth 2 (advent.pathfind/visit-all
|
||||||
(:collision (:background entities))
|
(:collision (:background entities))
|
||||||
[(int (:x (:ego entities))) (int (:y (:ego entities)))]
|
[(int (:x (:ego entities))) (int (:y (:ego entities)))]
|
||||||
[(int x) (int y)])))]
|
[(int x) (int y)])))
|
||||||
(assoc-in entities [:ego :actions] (when (seq path)
|
actions (when (seq path)
|
||||||
(concat
|
(conj
|
||||||
(vec (map #(walk-to-fn % :ego) (conj path [x y])))
|
(vec (map #(walk-to-fn % :ego) (conj path [x y])))
|
||||||
[(stop-fn :ego)])))))
|
(stop-fn :ego)))]
|
||||||
|
(assoc-in entities [:ego :actions] actions)))
|
||||||
(defn get-ego [screen]
|
(defn get-ego [screen]
|
||||||
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
||||||
ego {:right (animation 0.075 (for [i (range 8)]
|
ego {:right (animation 0.075 (for [i (range 8)]
|
||||||
|
|||||||
Reference in New Issue
Block a user