/
core.clj
62 lines (45 loc) · 1.18 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(ns ruin.core
(:use [ruin.ui :only [draw-ui ->UI]])
(:require [lanterna.screen :as s]))
(defonce game (ref nil))
(defn create-fresh-game []
(dosync
(let [scr (s/get-screen :swing {:cols 120
:rows 45
:font "Menlo"
:font-size 16})]
(ref-set game {:screen scr
:entities {}
:state :running
:uis [(->UI :start)]})
(s/start scr))))
(defn push-ui [])
(defn pop-ui [])
(defn draw-uis []
(let [game @game]
(dorun (map #(draw-ui % game) (:uis game)))
(s/redraw (:screen game))))
(defn draw-loop []
(draw-uis)
(Thread/sleep 500)
(when (:state @game)
(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))
(future (input-loop))))
(defn main []
(create-fresh-game)
(run-game))
(defn -main [& args]
(main))
(comment
(main))