the sheep can move closer to the player now.

This commit is contained in:
2014-10-02 12:26:29 -07:00
parent 6c0acd1ae6
commit a21d0cb6f3
6 changed files with 57 additions and 2 deletions

View File

@@ -67,6 +67,48 @@
~@forms))
(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])
final-x (int final-x)
final-y (int final-y)]
(run-action entities
(begin [this screen entities]
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 [delta-x (- final-x from-x)
delta-y (- final-y from-y)
distance (dist from-x from-y final-x final-y)
speed (* (or scale-x 1.0) 1.5)
moved-x (if (= 0.0 distance)
0
(* speed (/ delta-x distance)))
moved-y (if (= 0.0 distance)
0
(* 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]
#(start-animation screen
(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])]
(< (dist final-x final-y from-x from-y) 1)))
(terminate [this screen entities]
(stop screen entities target-id))
(can-skip? [this screen entities]
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])
final-x (int final-x)