 
 (defn move-player
   [state direction]
-  (swap! state
-         (fn [current]
-           (let [{:keys [player]} current
-                 [player-x player-y] player]
-             (assoc current
-                    :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)))))))
+  (when (= :playing (:game-state @state))
+    (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]

  [(pixels->cell (/ game-width 2))
   (- (pixels->cell game-height) 1)])

(defn initial-state
  []
  {:start-time (js/Date.)
   :state :playing
   :player start-position} )

(def keycode->key

  [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 handle-keyevent
  [state keyevent]
  (move-player state keyevent)
  (log-state @state))

(defn translate-keyboard-event
  [e]
