 
 (def time-flow (chan))
 
-(def game-state (atom {:rows (sorted-map)
+(def game-state (atom {:last-update 0
+                       :rows (sorted-map)
                        :tetrimino nil
                        :next-tetrimino (random-tetrimino)
                        :gravity-interval 500

   (doseq [block blocks]
     (draw-block ctx offset block))))

(defn render
  "Draws everything on the screen."
  [{t :tetrimino
    tn :next-tetrimino
    rows :rows
    score :score
    level :level}]
  (aset score-text "innerText" score)
  (aset level-text "innerText" level)
  (draw-background screen-ctx "#2a2f34")
  (draw-background preview-ctx "#3b4045")
  (when t (draw-blocks screen-ctx rendering-offset (tetrimino->blocks t)))
  (when tn (draw-blocks preview-ctx (tetrimino->blocks tn)))
  (draw-blocks screen-ctx rendering-offset (rows->blocks rows)))

(defn render-loop
  "Starts the rendering loop using requestAnimationFrame callback."
  []
  (render @game-state)
  (.requestAnimationFrame js/window render-loop))

(defn run-game-cycle
  "Puts everything together."

(def screen-height 440)
(def blocks-h 10)
(def blocks-v 24)
(def fps 30)
(def game-loop-freq 30)
(def render-freq (/ 1000 30))
(def block-size (/ screen-width blocks-h))
(def block-border-size 1)
(def rendering-offset [0 -2])
