Skip to content

Commit

Permalink
Add input handling in a separate thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjl committed Aug 4, 2012
1 parent 20d1191 commit fc2fd4c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ruin/core.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@
(recur))) (recur)))




(defn handle-input [input]
(when (= input \q)
(dosync (alter game dissoc :state))
(s/stop (:screen @game))))

(defn input-loop []
(handle-input (s/get-key-blocking (:screen @game)))
(when (:state @game)
(recur)))


(defn run-game [] (defn run-game []
(let [screen (:screen @game)] (let [screen (:screen @game)]
(future (draw-loop)) (future (draw-loop))
(s/get-key-blocking screen) (future (input-loop))))
(dosync (alter game dissoc :state))
(s/stop screen)))




(defn main [] (defn main []
Expand Down

0 comments on commit fc2fd4c

Please sign in to comment.