Skip to content

Commit 3f7668b

Browse files
committed
Quit by ESC.
Now you can quit the game by pressing ESC. But it looks like an exit flag, which I used to implement this feature, is not a part of the world. Maybe we should define a new entity or something.
1 parent 75576cf commit 3f7668b

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/hyperspace/game.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@
102102
(- radius 2)))))
103103
())))
104104

105+
(defn exit [world]
106+
(assoc world
107+
:exit true))
108+
105109
(defn update-world
106110
[{missiles :missiles
107111
planets :planets

src/hyperspace/ui.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
(= key Keyboard/KEY_DOWN)
4141
(decrease-power world 1)
4242

43+
(= key Keyboard/KEY_ESCAPE)
44+
(exit world)
45+
4346
(and (= key Keyboard/KEY_SPACE)
4447
(not (Keyboard/isRepeatEvent)))
4548
(fire world)
@@ -132,7 +135,8 @@
132135
[initial-world]
133136
(loop [time (get-time)
134137
world initial-world]
135-
(if (Display/isCloseRequested)
138+
(if (or (Display/isCloseRequested)
139+
(:exit world))
136140
(Display/destroy)
137141
(let [new-time (get-time)
138142
delta-time (- new-time time)

src/hyperspace/world.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@
116116
:planets ()
117117
:missiles ()
118118
:fragments ()
119-
:traces []}
119+
:traces []
120+
:exit false}
120121
generate-players
121122
generate-planets
122123
generate-missiles))

0 commit comments

Comments
 (0)