Added game restart option

master
Abhinav Sarkar 9 years ago
parent d78ff03952
commit b1730f4816
  1. 2
      resources/public/index.html
  2. 9
      src/cljs/frpong/core.cljs

@ -33,7 +33,7 @@ body {
<center>
<div id="screen">
<div>
<div id="state">press any key to start</div>
<div id="state">press &lt;space&gt; to start</div>
</div>
<svg id="canvas">
<circle id="ball" />

@ -260,20 +260,23 @@
(let [fps (int (/ 1000 (<! ticks)))
[x y] (<! pos)
[state score] (<! game-state)
state (condp = state
state-text (condp = state
:moving "Playing"
:collision "Playing"
:gameover "Game Over")]
(when-not (= fps fps-p)
(dom/set-text! fps-el fps))
(when-not (= state state-p)
(dom/set-text! state-el state))
(dom/set-text! state-el state-text))
(when-not (= score score-p)
(dom/set-text! score-el score))
(when (= state :gameover)
(do (dom/set-text! state-el "press <space> to restart")
(ev/listen-once! :keypress #(.reload (.-location js/window)))))
(doto ball-el
(dom/set-attr! "cx" x)
(dom/set-attr! "cy" y))
(recur fps state score))))
(recur fps state-text score))))
(go-loop
(dom/set-attr! lpaddle-el "y" (<! pl-pos)))
(go-loop

Loading…
Cancel
Save