   (doseq [entity (renderable-entities)]
     (draw entity)))
 
-
 (defn tap-print
   [text val]
   ;; (when val
   ;;   (println text))
   val)
+
+(defn object-center
+  [entity]
+  (let [[x y w h] (utils/position-and-bounds entity)]
+    [(int (+ x (/ w 2)))
+     (int (+ y ( / h 2)))]))
+
+(defn entity-proximity?
+  [e1 e2 minimum]
+  (let [[[x1 y1] [x2 y2]] (map object-center [e1 e2])
+        proximity (Math/sqrt (+ (Math/pow (- x1 x2) 2)
+                   (Math/pow (- y1 y2) 2)))]
+    ;; (println "obect centers:" (map object-center [e1 e2]) "proximity:" proximity "min:" minimum)
+    (<= proximity minimum)))
 
 (defn collide?
   [a b]

  ;;
  )


(defn position->corrds
  [[px py] width height shape-height shape-width]
  [(int (- (* width (/ px 100)) (/ shape-width 2)))
   (int (- (* height (/ py 100)) (/ shape-height 2)))])

(defn absolute-bounds
  [[w h] width height]
  [(int (* width (/ w 100)))
   (int (* height (/ h 100)))])

(defmulti draw (fn [e] (:shape (utils/find-component :renderable e))))
(defmethod draw :circle [e]
  (let [renderable (utils/find-component :renderable e)
        color (:color renderable)
        positionable (utils/find-component :positionable e)
        position (:position positionable)
        boundable (utils/find-component :boundable e)
        [w _] (:bounds boundable)
        canvas (:canvas @game-state)
        width (.-width canvas)
        height (.-height canvas)
        radius (int (* height (/ (/ w 2) 100)))
        surface (:surface @game-state)
        [x y] (position->corrds position width height (* 2 radius) (* 2 radius))]
    (set! (.-fillStyle surface) color)
    (.beginPath surface)
    (.arc surface x y radius 0 (* 2 Math/PI) true)

  (doseq [entity (sort-by z-order
                          (:entities @game-state))]
    (println entity)))

(defn trigger-entity!
  [entity]
  (replace-entity (assoc-in entity [:components :movable :velocity] 0.5)))

(defn try-activate!
  []
  (doseq [player (find-entities-by-component :controllable)]
    (doseq [entity (find-entities-by-component :triggerable)]
      (let [proximity (:proximity (utils/find-component :triggerable entity))]
        (when (entity-proximity? player entity proximity)
          (trigger-entity! entity))))))

(defn keyboard-handler
  [event]
