making moving speed dynamic based on scale.

This commit is contained in:
2014-09-23 15:54:09 -07:00
parent e2e426d108
commit c745eb4bf1

View File

@@ -81,20 +81,23 @@
entities) entities)
(continue [this screen entities] (continue [this screen entities]
(let [{from-x :x from-y :y :keys [left right] :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 [:background :entities target-id])
[[target-x target-y] remainder] @targets-left] [[target-x target-y] remainder] @targets-left]
(let [delta-x (- target-x from-x) (let [delta-x (- target-x from-x)
delta-y (- target-y from-y) delta-y (- target-y from-y)
distance (dist from-x from-y target-x target-y) distance (dist from-x from-y target-x target-y)
speed (* (or scale-x 1.0) 1.5)
moved-x (if (= 0.0 distance) moved-x (if (= 0.0 distance)
0 0
(* 1.5 (/ delta-x distance))) (* speed (/ delta-x distance)))
moved-y (if (= 0.0 distance) moved-y (if (= 0.0 distance)
0 0
(* 1.5 (/ delta-y distance)))] (* speed (/ delta-y distance)))]
(if (< distance 1) (if (< distance speed)
(do (swap! targets-left rest) (do (swap! targets-left rest)
entities) (-> 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] (update-in entities [:background :entities target-id]
#(start-animation screen #(start-animation screen
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)]) (assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])