              (reset! end true))))
 
 (defn main-view [state]
-  (r/with-let [game-state (r/cursor state [:game])]
+  (r/with-let [game-state (r/cursor state [:game])
+               max-score (r/cursor state [:max-score])]
     [:h1 "mRunner"]
     [:div.game-wrapper
      (if @game-state
-       [game-view game-state]
+       [game-view game-state max-score]
        [:button.start {:on-click #(reset! game-state initial-state)} "start"])]))
 
 

      (swap! state update :speed-y + (* gravity delta))
      (swap! state update-obstacles)
      (update-score state)
      (when (detect-collision @state) (swap! state assoc :game-over true)))
    (swap! state assoc :cur-time next-time))
  (when-not @end
    (js/requestAnimationFrame #(game-loop state end))))

(defn game-view [state]
  (r/with-let [end (atom false)
               keys [(events/listen js/window "keydown" #(handle-key state %))
                     (events/listen js/window "keyup" #(handle-key-up state %))]
               loop (js/requestAnimationFrame #(game-loop state end))]

    [:div.game
     (when (and (:pause @state) (not (:game-over @state))) [:div.pause "PAUSED"])
     (when (:game-over @state) [:div.game-over "GAME OVER"
                                [:button.restart {:on-click #(reset! state initial-state)} "restart"]])
     [:div.score (:score @state)]
     [:div.sky {:style {:background-position-x (/ (- (:pos-x @state )) 5)}}]
     [:div.road {:style {:background-position-x (- (:pos-x @state ))}}]
     [:div.runner {:class (when (:down @state) "down")

      (swap! state update :score + 10)
      (swap! state assoc-in [:obstacles 0 :scored] true))))

(defn game-loop [state end max-score]
  (let [{:keys [cur-time]} @state
        next-time (js/performance.now)
        delta (- next-time cur-time)]
