distance.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
[advent.pathfind]
|
||||
[advent.actions :as actions]
|
||||
[advent.screens.dialogue :as dialogue]
|
||||
[advent.utils :as utils]
|
||||
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]])
|
||||
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
|
||||
[com.badlogic.gdx.graphics.g2d TextureRegion]
|
||||
@@ -53,11 +54,6 @@
|
||||
(update-in entities [:room :entities target-id] #(start-animation screen % :stand)))
|
||||
|
||||
|
||||
(defn dist [x1 y1 x2 y2]
|
||||
(let [dx (- x1 x2)
|
||||
dy (- y1 y2)]
|
||||
(Math/sqrt (+ (* dx dx) (* dy dy)))))
|
||||
|
||||
(defmacro run-action [entities & forms]
|
||||
`(let [c# (chan)]
|
||||
(do
|
||||
@@ -79,7 +75,7 @@
|
||||
(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)
|
||||
distance (utils/dist from-x from-y final-x final-y)
|
||||
speed (* (or scale-x 1.0) 1.5)
|
||||
moved-x (if (= 0.0 distance)
|
||||
0
|
||||
@@ -102,7 +98,7 @@
|
||||
|
||||
(done? [this screen entities]
|
||||
(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)))
|
||||
(< (utils/dist final-x final-y from-x from-y) 1)))
|
||||
|
||||
(terminate [this screen entities]
|
||||
(stop screen entities target-id))
|
||||
@@ -131,7 +127,7 @@
|
||||
[[target-x target-y] remainder] @targets-left]
|
||||
(let [delta-x (- target-x from-x)
|
||||
delta-y (- target-y from-y)
|
||||
distance (dist from-x from-y target-x target-y)
|
||||
distance (utils/dist from-x from-y target-x target-y)
|
||||
speed (* (or scale-x 1.0) 1.5)
|
||||
moved-x (if (= 0.0 distance)
|
||||
0
|
||||
@@ -155,7 +151,7 @@
|
||||
|
||||
(done? [this screen entities]
|
||||
(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)))
|
||||
(< (utils/dist final-x final-y from-x from-y) 1)))
|
||||
|
||||
(terminate [this screen entities]
|
||||
(stop screen entities target-id))
|
||||
|
||||
Reference in New Issue
Block a user