Skip to content

Instantly share code, notes, and snippets.

@verma
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verma/304538e144216453809a to your computer and use it in GitHub Desktop.
Save verma/304538e144216453809a to your computer and use it in GitHub Desktop.
(def level ["^------$"
"< >"])
(def symbols
{ \^ '(0 0 64 64)
\- '(64 0 64 64)
\< '(0 64 64 64)
\> '(128 64 64 64)
\ '(64 64 64 64)
\$ '(128 0 64 64) })
(defn game [state ctx]
(doseq [[line row] (map list level (iterate inc 0))]
(doseq [[c i] (map list line (iterate inc 0))]
(let [[sx sy sw sh] (get symbols c)]
(blit! ctx image sx sy sw sh (* 64 i) (* 64 row))))))
@alandipert
Copy link

An alternative:

(def transpose (partial map vector))

(defn game [state ctx]
  (doseq [[line row] (transpose level (range))
          [c i]      (transpose line (range))
          :let       [[sx sy sw sh] (symbols c)]
          (blit! ctx image sx sy sw sh (* 64 i) (* 64 row))]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment