diff --git a/resources/public/index.html b/resources/public/index.html
index 50ec202..9e2badb 100644
--- a/resources/public/index.html
+++ b/resources/public/index.html
@@ -13,7 +13,9 @@
Position:
Velocity:
diff --git a/src/cljs/frpong/core.cljs b/src/cljs/frpong/core.cljs
index 4849ba5..673af84 100644
--- a/src/cljs/frpong/core.cljs
+++ b/src/cljs/frpong/core.cljs
@@ -1,5 +1,5 @@
(ns frpong.core
- (:require [frpong.helpers :as h :refer [log]]
+ (:require [frpong.helpers :as h]
[cljs.core.async :as async
:refer [! chan put! close! sliding-buffer dropping-buffer timeout]]
[domina :as dom :refer [log]]
@@ -42,7 +42,7 @@
(recur t))))
c))
-(defn positioner [tick-chan vel-chan pos-chan-in pos-chan-out]
+(defn ball-positioner [tick-chan vel-chan pos-chan-in pos-chan-out]
(go-loop
(let [tick ( p (- size padding)) (- (abs v))
@@ -65,33 +65,65 @@
vel-yn (adjust-v yn vel-y height)]
(>! vel-chan-out [vel-xn vel-yn]))))
-(defn render-loop [pos-chan vel-chan]
+(defn key-chan [keycodes]
+ (let [source (h/event-chan :keydown)
+ c (chan)]
+ (go-loop
+ (let [kc (:keyCode (! c (keycodes kc)))))
+ c))
+
+(defn paddle-positioner [keycodes max-y movement pos-chan-in pos-chan-out]
+ (let [key-chan (key-chan keycodes)]
+ (go-loop
+ (let [dir (! pos-chan-out (max (- pos movement) 0))
+ :down (>! pos-chan-out (min (+ pos movement) max-y)))))))
+
+(defn render-loop [[pos-chan vel-chan pl-pos-chan pr-pos-chan]]
(go-loop
(let [[x y] (map int (! c v)
- (recur ::throttling last
- (conj cs control)))
- ::throttling (recur state v cs))
- sync (if last
- (do (>! c last)
- (recur state nil
- (conj (pop cs) control)))
- (recur ::init last (pop cs))))))))
+ (loop [state ::init last nil]
+ (let [[v sc] (alts! [source control])]
+ (condp = sc
+ source (condp = state
+ ::init (do (>! c v)
+ (recur ::throttling last))
+ ::throttling (recur state v))
+ control (if last
+ (do (>! c last)
+ (recur state nil))
+ (recur ::init last))))))
c))
(defn debounce
@@ -153,7 +148,7 @@
(defn event-chan [event-type]
(let [c (chan)]
- (ev/listen! js/document event-type #(put! c %))
+ (ev/listen! event-type #(put! c %))
c))
(defn frame-chan []