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/8115304 to your computer and use it in GitHub Desktop.

Select an option

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