Skip to content

Instantly share code, notes, and snippets.

@aamedina
Last active January 1, 2016 07:59
Show Gist options
  • Select an option

  • Save aamedina/8114944 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/8114944 to your computer and use it in GitHub Desktop.
(defn handle-player-movement
[key-handler]
(let [coords (atom [0 0])]
(.addEventListener key-handler goog.events.KEY
(fn [e]
(let [dir (case (.-keyCode e)
KeyCodes.UP :up
KeyCodes.DOWN :down
KeyCodes.RIGHT :right
KeyCodes.LEFT :left)]
(match [dir]
:up (swap! coords ...)
:down (swap! coords ...)
:right (swap! coords ...)
:left (swap! coords ...)))))
coords))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment