Skip to content

Commit

Permalink
Improve game loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Odinodin committed Aug 12, 2015
1 parent 845e3e3 commit 184d675
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions snake/project.clj
Expand Up @@ -49,7 +49,7 @@

:figwheel {
:http-server-root "public" ;; default and assumes "resources"
:server-port 3449 ;; default
:server-port 4000 ;; default
:css-dirs ["resources/public/css"] ;; watch and update CSS

:nrepl-port 7888})
:nrepl-port 4444})
17 changes: 8 additions & 9 deletions snake/src/canvas_fn_snake/core.cljs
Expand Up @@ -183,14 +183,13 @@
(canv/animate animate)
(render canvas @model)))


(defn game-loop [stop-chan]
"Separate game loop"
(go-loop []
(alt! (timeout 40) (do (swap! model update-model) (recur))
stop-chan (println "Stopping game loop"))))
(def speed 5000)

;; Start the game
(defonce stop-game-chan (chan)) ;; Designated channel for stopping the game from Figwheel when reloading code
(game-loop stop-game-chan)
(animate)
(defonce game-loop
(go-loop []
(<! (timeout speed))
(swap! model update-model)
(recur)))

(defonce u (animate))
2 changes: 1 addition & 1 deletion snake/src/dev/figwheel.cljs
Expand Up @@ -4,5 +4,5 @@

(defn reload-hook []
(fn []
(put! snake-core/stop-game-chan "stop")
#_(put! snake-core/stop-game-chan "stop")
(print "reloaded")))

0 comments on commit 184d675

Please sign in to comment.