 
 (extend-type Paddle
   IControllable
-  (control! [{:keys [y vy] :as paddle} event]
-    (case event
-      :up (assoc paddle :y (- y vy))
-      :down (assoc paddle :y (+ y vy))
+  (control! [{:keys [y vy height] :as paddle} event]
+    (condp = event
+      :up
+      (if (> (- y vy) 0) (assoc paddle :y (- y vy)) paddle)
+
+      :down
+      (if (< (+ y vy height) SCALE-H ) (assoc paddle :y (+ y vy)) paddle)
+
+      :else
       paddle)))
 
 ;;-----------------------------------------------------------------------------


(def state
  ;; Order matters
  (atom {:background (Rect. 0 0 SCALE-W SCALE-H "black")   ;; use div behind canvas
         :border     (Frame. 0 0 SCALE-W SCALE-H "#333" 2) ;; use div behind canvas
         :paddle-1   (Paddle. 20 (- SCALE-H 120) 20 100 2 "dodgerblue")
         :paddle-2   (Paddle. (- SCALE-W 40) 20 20 100 2 "peru")
         :ball       (Ball. 400 225 13 3 2 "lime")}))

;;-----------------------------------------------------------------------------

(ns canvas.main
  (:require-macros
   [cljs.core.async.macros :refer [go-loop]])
  (:require
   [cljs.core.async :refer [chan <! put!]]))

(enable-console-print!)

;;-----------------------------------------------------------------------------
;; Constants
;;-----------------------------------------------------------------------------

(def SCALE-W 800)
(def SCALE-H 450)

(def KEYBOARD
  {40 :down
   38 :up
   37 :paddle-1
   39 :paddle-2})

;;-----------------------------------------------------------------------------
;; DOM
