     (apply (.-bgColorRgb term) bgcolor)
     (.moveTo        term x y char)))
 
-(defn get-block [level coords]
-  (let [[x y] coords]
-    (get-in level [x y])))
+(defn fov [character]
+  (let [{:keys [x y direction]} character
+        [x y] (map inc [x y])
+        ends (end-points character)
+        lines (map #(let [dx (first %)
+                          dy (second %)
+                          start #js[x y]
+                          end   #js[dx dy]]
+                      (js->clj (bresenham start end))) ends)]
+    lines))
 
+(defn viewable-coords [character level]
+  (let [fov-blocks (fov character)
+        viewable-coords (map (partial shorten-line level) fov-blocks)]
+    (apply concat viewable-coords)))
 
 (defn dimmed-blocks [level coords]
   (let [flattened-level (flatten level)

    (partial draw-x term) line))

(defn shorten-line [level line]
  (take-while #(let [[x y] %
                     x (min (dec width)  (max 0 (dec x)))
                     y (min (dec height) (max 0 (dec y)))
                     current-block (get-in level [x y])]
                 (not (current-block :solid))
                 ) line))

(defn fov [character]
  (let [{:keys [x y direction]} character
        [x y] (map inc [x y])
        ends (end-points character)
        lines (map #(let [dx (first %)
                          dy (second %)
                          start #js[x y]
                          end   #js[dx dy]]
                      (js->clj (bresenham start end))) ends)]
    lines))

(defn draw-block [term block]
  (let [{:keys [x y solid inhabitants color]} block

    (map #(if (block-not-in-coords %) (dim-block %) (lit-block %)) flattened-level)
    ))

(defn show-screen [term level character]
  (defn callback [error] (when error (println error)))

  (def new-blocks
    (->> level
        (viewable-coords character)
        (dimmed-blocks level)
        (run! #(draw-block term %))
        ))

  (.color256    term 7)
  (.bgColor256  term 0)
