Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add input handling in a separate thread.

  • Loading branch information...
commit fc2fd4c0d781f4610fde1154127b9f5bdb531972 1 parent 20d1191
@sjl authored
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/ruin/core.clj
View
15 src/ruin/core.clj
@@ -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 []
Please sign in to comment.
Something went wrong with that request. Please try again.