 (def game-x-cells (pixels->cell game-width))
 (def game-y-cells (pixels->cell game-height))
 
-(defn surface-element
+(def surface
+  (let [surface (dom/getElement "surface")]
+    (set! (.-width surface) game-width)
+    (set! (.-height surface) game-height)
+    surface))
+(def draw-context (.getContext surface "2d"))
+
+(def start-position
+  [(pixels->cell (/ game-width 2))
+   (- (pixels->cell game-height) 1)])
+
+(defn initial-state
   []
-  (dom/getElement "surface"))
+  {:start-time (js/Date.)
+   :state :playing
+   :player start-position} )
 
 (def keycode->key
   {kcs/SPACE :space

  {:blue "#127496"})

(defn log-state
  [{:keys [surface-width surface-height surface player]}]
  (let [[player-x player-y] player]
    (.log js/console "surface width:" surface-width
          "surface height:" surface-height)
    (.log js/console "surface:" surface)
    (.log js/console "player x" player-x "player y" player-y)))

(defn draw-square

                  :marginTop (px top)
                  :marginLeft (px left)})))

(defn setup-events
  [state]
  (let [timer (goog.Timer. 200)]
    (events/listen timer goog.Timer/TICK (partial check-game state))
    (events/listen js/window event-type/RESIZE resize)
    (events/listen js/window event-type/KEYDOWN (partial keydown state))
    (.start timer)))

(defn main
  []
  (let [state (atom (initial-state))]
    (setup-events state)
    (resize)
    (render-world state)))

(main)
