                   []))]
     (conj (apply conj (conj [] backgr) boxes) player)))
 
+(defn collision [entities]
+  (let [backgr (first entities)
+        player (last entities)
+        boxes (try              
+                (vec (drop 1 (drop-last entities)))                
+                (catch NullPointerException e
+                  []))]
+    (if (has-collide player boxes)
+      (throw (Exception. "Game over"))
+      (conj (apply conj (conj [] backgr) boxes) player))))
 
 (defscreen main-screen
   :on-show

  (:require [play-clj.core :refer :all]
            [play-clj.g2d :refer :all]))


(defn move [screen entity]
  (cond
    (= (:key screen) (key-code :dpad-up)) (if (<
                                                (+ (:y entity) 30) 
                                                (- 600 (:height entity)))
                                            (assoc entity :y (+ (:y entity) 30))
                                            (assoc entity :y  (- 600 (:height entity))))              
    (= (:key screen) (key-code :dpad-down)) (if (>
                                                (- (:y entity) 30) 
                                                0)
                                            (assoc entity :y (- (:y entity) 30))
                                            (assoc entity :y 0))         
    (= (:key screen) (key-code :dpad-right)) (if (<
                                                (+ (:x entity) 30) 
                                                (- 800 (:width entity)))
                                            (assoc entity :x (+ (:x entity) 30))
                                            (assoc entity :x  (- 800 (:width entity))))                 
    (= (:key screen) (key-code :dpad-left)) (if (>
                                                (- (:x entity) 30) 
                                                0)
                                            (assoc entity :x (- (:x entity) 30))
                                            (assoc entity :x 0))))



  :on-render
  (fn [screen entities]
    (clear!)
    (render! screen 
             (->
               (moving entities)
               (collision)
               ))) 
       
  :on-timer
  (fn [screen entities]
