                  nil
                  (partial draw-rect (:bg colours))))
 
+(defn update-ball [event world-state ent]
+  (let [{:keys [vx vy w h]} (:value ent)]
+    (-> ent
+        (update-in [:value :x] (fn [old-x]
+                                 (clamp (+ old-x vx) 0
+                                        (- (:w canvas-size) w))))
+        (update-in [:value :y] (fn [old-y]
+                                 (clamp (+ old-y vy) 0
+                                        (- (:h canvas-size) h)))))))
+
 (def ball
-  (let [ball-dim {:x 0
-                  :y 0
-                  :w ball-size
-                  :h ball-size}]
+  (let [ball-dim {:x  0
+                  :y  0
+                  :w  ball-size
+                  :h  ball-size
+                  :vx 0
+                  :vy 0}]
     (canvas/entity (center-ball ball-dim canvas-size)
-                   nil
+                   update-ball
                    (partial draw-rect (:ball colours)))))
 
 (defn update-player-paddle

  (assoc world-state
    :mouse-coords (client->canvas-coords canvas (client-coords event))))

(defn render-scene
  "Loop over the entities calling each ones draw fn."
  [ctx world-state]

      :initial-state {:entities     [background player-paddle ai-paddle ball]
                      :mouse-coords [0 0]}

      :on-tick       update-state
      :on-mousemove  (partial update-mouse-coords canvas)
      :on-click      serve-ball
      :event-target  canvas
      :to-draw       (partial render-scene ctx)))))
