Skip to content

Instantly share code, notes, and snippets.

@kornysietsma
Created September 28, 2013 11:34
Show Gist options
  • Save kornysietsma/6741187 to your computer and use it in GitHub Desktop.
Save kornysietsma/6741187 to your computer and use it in GitHub Desktop.
simple game loop that reads regular ajax results and also updates on every animation frame
(defn game-loop []
(let [anim-chan (au/anim-ch active)
ajax-chan (au/ajax-loop "world" slowth active)]
(go
(loop [state {:world {} :timestamp (js-now)}]
(when @active
(let [next-state
(alt!
anim-chan ([val] (do
(graphics/draw-map
ctx (:world state) (scaled-time val (:timestamp state)))
state)) ; no state change
ajax-chan ([val] {:world val :timestamp (js-now)}))]
(recur next-state)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment