                        :medium "2"
                        "1")
                      ".png")
-                x y width height 0 false)
+                x y width height)
     (draw-meta canvas-element contents meta x y width height)))
 
 (defn- draw-food
   [canvas-element contents meta x y width height]
   (draw-image canvas-element
               "food_cherry.png"
-              x y width height 0 false)
+              x y width height)
   (draw-meta canvas-element contents meta x y width height))
 
 (defn- draw-poison
   [canvas-element contents meta x y width height]
   (draw-image canvas-element
               "poison_vial_2.png"
-              x y width height 0 false)
+              x y width height)
   (draw-meta canvas-element contents meta x y width height))
 
 (defn- draw-open

                    :s "front"
                    :n "back"
                    "right")
        flipped (= orientation :w)]

    ;; Always draw the base wombat
    (draw-image canvas-element
                (str "wombat_" color "_" direction ".png")
                x y width height 0
                flipped)

    ;; See if we need to add any meta to the wombat
    (doseq [{type :type} (sort-meta meta)]

      (case type
        :shot
        (draw-image canvas-element
                    (str "wombat_" color "_" direction "_fire.png")
                    x y width height 0
                    flipped)

        :explosion
        (draw-image canvas-element
                    "explosion.png"
                    x y width height 0 false)

        :smoke
        (draw-image canvas-element
                    "smoke.png"
                    x y width height 0 false)

        (js/console.log type)))))


  (:require [re-frame.core :as re-frame]
            [wombats-web-client.utils.canvas :as canvas]))

(defonce spritesheet-png "/images/spritesheet.png")

(defn- draw-image
  [canvas-element img-name x y width height]
  (let [spritesheet (re-frame/subscribe [:spritesheet])
        sprite-info (get @spritesheet (keyword img-name))
        frame (:frame sprite-info)]
    (when-not (nil? frame)
      (let [img (js/Image.)]
        (set! (.-src img) spritesheet-png)
        (.requestAnimationFrame js/window
                                (fn []
                                  (canvas/draw-image canvas-element
                                                     img
                                                     (:x frame)
                                                     (:y frame)
                                                     (:w frame)
                                                     (:h frame)
                                                     x
                                                     y
                                                     width
                                                     height)))))))

(defn- draw-image-rotated
  [canvas-element img-name x y width height rotation]
  (let [spritesheet (re-frame/subscribe [:spritesheet])
        sprite-info (get @spritesheet (keyword img-name))
        frame (:frame sprite-info)]
    (when-not (nil? frame)
      (let [img (js/Image.)]
        (set! (.-src img) spritesheet-png)
        (.requestAnimationFrame js/window
                                (fn []
                                  (canvas/draw-image-rotated canvas-element
                                                             img
                                                             (:x frame)
                                                             (:y frame)
                                                             (:w frame)
                                                             (:h frame)
                                                             x y
                                                             width
                                                             height
                                                             rotation)))))))

(defn- draw-image-flipped-horizontally
  [canvas-element img-name x y width height]

  (let [spritesheet (re-frame/subscribe [:spritesheet])
        sprite-info (get @spritesheet (keyword img-name))
        frame (:frame sprite-info)]
    (when-not (nil? frame)
      (let [img (js/Image.)]
        (set! (.-src img) spritesheet-png)
        (.requestAnimationFrame js/window
                                (fn []
                                  (canvas/draw-image-flipped-horizontally canvas-element
                                                                          img
                                                                          (:x frame)
                                                                          (:y frame)
                                                                          (:w frame)
                                                                          (:h frame)
                                                                          x y
                                                                          width
                                                                          height)))))))

(defn- draw-background
  "This draws the background of a cell (only called for cells that need it)"
  [canvas-element x y width height]
  (draw-image canvas-element
              "arena_bg.png"
              x y width height))

(defn- meta-value
  "Gets a score for a meta type for sorting draw level"
