     (.drawImage draw-context sprite x y size size)))
 
 (defn draw-text
-  ([state x y text] (draw-text state x y text "top"))
-  ([state x y text baseline] (draw-text state x y text baseline "right"))
-  ([state x y text baseline align]
+  ([state x y text] (draw-text state x y text "middle"))
+  ([state x y text baseline] (draw-text state x y text baseline "center"))
+  ([state x y text baseline align] (draw-text state x y text baseline align "4em"))
+  ([state x y text baseline align font-size]
    (let [[x y] (cell->coords x y)]
-     (set! (.-font draw-context) "bold 1.5em sans-serif")
+     (set! (.-font draw-context) (str "bold " font-size " sans-serif"))
      (set! (.-textBaseline draw-context) baseline)
      (set! (.-textAlign draw-context) align)
      (.fillText draw-context text x y))))

  [inventory]
  (>= (bone-count inventory) number-bones-needed))

(defmulti render :game-state)

(defmethod render :playing
  [state]
  (let [{:keys [player start-time item-locations inventory]} state
        countdown (- time-limit (elapsed-time start-time))
        [player-x player-y] player]
    (doseq [x (range game-x-cells) y (range game-y-cells)]
      (draw-sprite state x y cell-size :grass))
    (doseq [[[x y] sprite] item-locations]
      (draw-sprite state x y cell-size sprite))
    (draw-sprite state player-x player-y cell-size :player)


(defn move-player
  [state direction]
  (swap! state
         (fn [current]
           (let [{:keys [player inventory item-locations]} current
                 [player-x player-y] player
                 new-player (boundary
                              (condp = direction
                                :left [(dec player-x) player-y]
                                :right [(inc player-x) player-y]
                                :forward [player-x (dec player-y)]
                                :back [player-x (inc player-y)]
                                player))
                 item-at-player (get item-locations new-player)
                 new-inventory (if item-at-player
                                 (conj inventory item-at-player)
                                 inventory)
                 new-item-locations (if item-at-player
                                      (dissoc item-locations new-player)
                                      item-locations)]
             (assoc current
                    :player new-player
                    :inventory new-inventory
                    :item-locations new-item-locations)))))

(defn timeup?
  [start-time]
  (>= (elapsed-time start-time) time-limit))

(defn playing?
  [{:keys [game-state]}]
  (= game-state :playing))

(defn check-game
  [state]
  (when (playing? @state)
    (swap! state
           (fn [current]
             (let [{:keys [game-state start-time inventory]} current]
               (assoc current :game-state
                      (cond
                        (enough-bones? inventory) :win
                        (timeup? start-time) :lose
                        :else game-state)))))))

(defn start-game
  [state]
  (swap! state
         (fn [current]
           (assoc current
                  :game-state :playing
                  :start-time (js/Date.)))))

(defn reset-game
  [state keyevent]
  (when (= keyevent :new-game)
    (reset! state (initial-state))))

(defn handle-keyevent
  [state keyevent]
  (let [{:keys [game-state]} @state]
    (condp = game-state
      :playing (move-player state keyevent)
      :start (start-game state)
      (reset-game state keyevent)))
  (log-state @state))

(defn translate-keyboard-event
