      :y (+ (:y (:position hero)) y-delta)} ))
 
 (defn ensure-screen-position [hero direction]
+  {:pre [(spec/valid? ::hero hero)]}
   ;; keep the hero on-screen
   (let [new-pos (proposed-position hero direction)]
     (if (move-to? config/screen-size (:size hero) new-pos)

    :else true))

(defn proposed-position [hero direction]
  (let [speed   (:speed hero)
        x-delta (cond (= :right direction)       speed
                      (= :left  direction) (* -1 speed)


(defn create
  ([name images initial-x initial-y size-x size-y]
   {:id         (gensym "char-")
    :name       name
    :images     images
    :animation  :stand
    :position   {:x initial-x :y initial-y}
    :size       {:x size-x    :y size-y}
    :speed      2
    :halo-angle (rand-int 360)
    })
  ([name initial-x initial-y]
   (create name (load-images) initial-x initial-y (:x config/hero-size) (:y config/hero-size))))

(defn- move-to? [screen-size sprite-size new-position]
  {:pre [(spec/valid? ::position screen-size)  ; throw on bogus input
         (spec/valid? ::position sprite-size)
         (spec/valid? ::position new-position)]}
  (cond
    (> (:x new-position) (- (:x screen-size) (:x sprite-size))) false
    (> (:y new-position) (- (:y screen-size) (:y sprite-size))) false
