Permalink
Browse files

Add input handling in a separate thread.

  • Loading branch information...
1 parent 20d1191 commit fc2fd4c0d781f4610fde1154127b9f5bdb531972 @sjl committed Aug 4, 2012
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/ruin/core.clj
View
@@ -33,12 +33,21 @@
(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 []
(let [screen (:screen @game)]
(future (draw-loop))
- (s/get-key-blocking screen)
- (dosync (alter game dissoc :state))
- (s/stop screen)))
+ (future (input-loop))))
(defn main []

0 comments on commit fc2fd4c

Please sign in to comment.