 
 (defn in-lava [app]
   (let [position (get-in app [:hero :position])]
-    (some #{4} (current-blocks position))
+    (some #{4} (blocks position))
     )
   )
 
 (defn move-horizontally [hero]
   (let [left-position (get-in hero [:position :left])]
-    (condp = (hero :move)
-      :left (when (can-move :left @app-state)
-              (update-in hero [:position :left] - 5)
-              )
-      :right (when (can-move :left @app-state)
-               (update-in hero [:position :left] + 5)
-               )
+    (if (moving? hero)
+      (update-in hero [:position :left] (fn [old-left] (+ old-left (hero :dx))))
       hero
       )))
 
+(defn gravity [current-vertical jump-time hero]
+  (let [last-bottom (get-in hero [:position :bottom])
+        initial-bottom (get-in hero [:jump :bottom])
+        dt (/ (- (.getTime (js/Date.)) jump-time) 1000)
+        vforce (* 1000 dt)
+        gforce (/ (* 2000 dt dt) 2)
+        height (+ (- vforce gforce) initial-bottom)
+        ]
+      (update-in hero [:position :bottom] (fn [_] height))
+
+      )
+  )
+
+;; (defn grav [hero]
+;;   (let [vertical-velocity (get-in hero [:vertical-velocity])]
+;;     (if vertical-velocity
+;;       (let [new-hero (update-in hero [:vertical-velocity] (fn [original] (- original 5)))
+;;             new-velocity (get-in new-hero [:vertical-velocity])]
+;;         (update-in (get-in hero [:position :bottom] (fn [original] (+ original new-velocity))))
+;;         )
+;;       hero
+;;       )
+;;     )
+;;   )
+
 (defn move-vertically [hero]
   (let [current-vertical (get-in hero [:position :bottom])
-        current-block-no (most-supportive-block (beneath-1px (get-in hero [:position])))
         jump-time (get-in hero [:jump :start])]
     (if jump-time
       (gravity current-vertical jump-time hero)
-      (if (on-solid-ground? (get-in hero [:position]))
-        hero
-        (update-in hero [:position :bottom] - 5)
-        )
-      )
-    )
-  )
-
-(defn x-move-vertically [hero]
-  (let [current-vertical (get-in hero [:position :bottom])
-        current-block-no (most-supportive-block (beneath-1px (get-in hero [:position])))
-        jump-time (get-in hero [:jump :start])]
-    (if (on-solid-ground? (get-in hero [:position]))
-      (if jump-time
-        (let [new-hero (update-in hero [:position :bottom] (fn [_] (new-gravity current-vertical jump-time app-state)))]
-          (if (< (get-in new-hero [:position :bottom]) -5)
-            (update-in new-hero [:jump :start] (fn [_] nil))
-            new-hero
-            )
-          )
-        hero
-        )
-
-      )
-
-    ;; (if-let [jump-time (get-in hero [:jump :start])]
-    ;;   (update-in hero [:position :bottom] (fn [_] (new-gravity current-vertical jump-time app-state)))
-    ;;   (if (on-solid-ground? (get-in hero [:position]))
-    ;;     hero
-    ;;     (let [new-hero (update-in hero [:position :bottom] - 5)]
-    ;;       (if (< (get-in new-hero [:position :bottom]) current-vertical)
-    ;;         (println "FALLING")
-    ;;         (update-in new-hero [:jump :start] (fn [_] nil))
-    ;;         new-hero
-    ;;         ))
-    ;;     )
-    ;;   )
-    ))
-
-(defn update-hero [app new-hero]
-  (om/update! app [:hero] new-hero))
+      hero
+      )
+    )
+  )
+
+(defn ground-resistance [hero]
+  (let [position (get-in hero [:position])
+        coord-y (vertical-coord position)
+        current-tiles (blocks position)]
+    (if (some #{1} current-tiles)
+      (let [new-hero (update-in hero [:position :bottom] (fn [_] (* (+ 1 coord-y) 70)))]
+        (update-in new-hero [:jump :start] (fn [_] nil)))
+      hero
+      )
+    ))
+
+(defn block-resistance [hero]
+  (let [position (get-in hero [:position])
+        coords-x (horizontal-coords position)
+        current-tiles (blocks position)]
+    (if (some #{1} current-tiles)
+      (condp = (moving? hero)
+        :left (update-in hero [:position :left] (fn [_] (* (+ (coords-x :left) 1) 70)))
+
+        :right (update-in hero [:position :left] (fn [_] (* (- (coords-x :left) 1) 70))))
+      hero
+      )
+    ))
+
+(defn lava-damage [hero]
+  hero)
+
+(defn spike-damage [hero]
+  hero)
+
+(defn off-screen [hero]
+  hero)
 
 (defn hero [app owner]
   (reify


(defn stop-moving [e app]
  (condp = (aget e "keyCode")
    88 (om/update! app [:hero :move] false)
    90 (om/update! app [:hero :move] false)
    nil
    )
  )

     ]
    ))

(defn vertical-coord [position]
  (let [bottom (position :bottom)]
     (floor (/ bottom 70))
     ))

(defn horizontal-coords [position]
  (let [left (position :left)]
    {
     :left (floor (/ (+ left 20) 70))
     :right (floor (/ (+ left 54) 70))
     }

    ))

(defn blocks [position]
  (let [[left right] (hero-feet-coords position)
        app @app-state]
    [(get-in app (into [:grid] left)) (get-in app (into [:grid] right))]
