From 25ab05ede066854ec714669ac6fa482df110300b Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Wed, 25 Sep 2013 22:05:07 +0530 Subject: [PATCH] Cleaned up code, fixed collision detection --- resources/public/index.html | 1 + src/cljs/frpong/core.cljs | 74 ++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/resources/public/index.html b/resources/public/index.html index 9a74b2d..f5f239c 100644 --- a/resources/public/index.html +++ b/resources/public/index.html @@ -10,6 +10,7 @@
FPS:
Position:
+
Velocity:
diff --git a/src/cljs/frpong/core.cljs b/src/cljs/frpong/core.cljs index 9ea8b28..ad50067 100644 --- a/src/cljs/frpong/core.cljs +++ b/src/cljs/frpong/core.cljs @@ -30,6 +30,8 @@ ;; | renderer | ;; +----------+ +(defn abs [x] (.abs js/Math x)) + (defn positioner [tick-chan vel-chan pos-chan-in pos-chan-out] (go-loop (let [tick ( p (- size padding)) (- (abs v)) + :else v)) + tick ( xn padding) (< xn (- width padding))) vel-x (- vel-x)) - vel-yn (if (and (> yn padding) (< yn (- height padding))) vel-y (- vel-y))] + vel-xn (adjust-v xn vel-x width) + vel-yn (adjust-v yn vel-y height)] (>! vel-chan-out [vel-xn vel-yn])))) +(defn render-loop [pos-chan vel-chan] + (go-loop + (let [[x y] (map int (! pos-chan init-pos)) - (go (>! vel-chan init-vel)) - - (go-loop - (let [[x y] (map int (