diff --git a/resources/public/index.html b/resources/public/index.html index 4ac2be2..95f5b57 100644 --- a/resources/public/index.html +++ b/resources/public/index.html @@ -10,8 +10,6 @@
Frame:
FPS:
-
Position:
-
Velocity:
State:
diff --git a/src/cljs/frpong/core.cljs b/src/cljs/frpong/core.cljs index 869060c..1c837cd 100644 --- a/src/cljs/frpong/core.cljs +++ b/src/cljs/frpong/core.cljs @@ -1,9 +1,7 @@ (ns frpong.core (:require [frpong.helpers :as h] - [cljs.core.async :as async - :refer [! chan put! close! sliding-buffer dropping-buffer timeout]] - [domina :as dom :refer [log]] - [domina.events :as ev]) + [cljs.core.async :refer [! chan put!]] + [domina :as dom :refer [log]]) (:require-macros [cljs.core.async.macros :as m :refer [go]] [frpong.core :refer (go-loop)])) ;; @@ -44,45 +42,51 @@ (defn ball-positioner [ticks vel pos-in pos-out] (go-loop - (let [tick (! pos-out pos-next)))) +(defn paddle-positioner [keycodes max-y movement pos-in pos-out] + (let [keys (h/key-chan keycodes)] + (go-loop + (let [pos (! pos-out + (condp = ( y (- height padding)) :collision-right - :else :moving)) + in-y-range? (fn [y p-pos] (and (> y (+ p-pos padding)) + (< y (- (+ p-pos paddle-size) padding)))) detect-x-collision (fn [x y pl-pos pr-pos] (cond - (< x (+ paddle-width padding)) - (if (and (> y (+ pl-pos padding)) - (< y (- (+ pl-pos paddle-size) padding))) - :collision-left - :gameover) - (> x (- width (+ paddle-width padding))) - (if (and (> y (+ pr-pos padding)) - (< y (- (+ pr-pos paddle-size) padding))) - :collision-right - :gameover) - :else :moving))] + (< x ef-paddle-width) + (if (in-y-range? y pl-pos) :collision-left :gameover) + (> x (- width ef-paddle-width)) + (if (in-y-range? y pr-pos) :collision-right :gameover) + :else :moving)) + detect-y-collision (fn [y] (cond + (< y padding) :collision-left + (> y (- height padding)) :collision-right + :else :moving))] (go-loop - (let [tick (! vel-out [vel-xn vel-yn]) @@ -93,27 +97,14 @@ (= bs-y :collision-left) (= bs-y :collision-right)) :collision :else :moving)))))) -(defn paddle-positioner [keycodes max-y movement pos-in pos-out] - (let [keys (h/key-chan keycodes)] - (go-loop - (let [pos (! pos-out - (condp = (