|
|
@ -1,18 +1,17 @@
|
|
|
|
(ns topdown2d.objects)
|
|
|
|
(ns topdown2d.objects)
|
|
|
|
|
|
|
|
|
|
|
|
(defn in? [obj box]
|
|
|
|
(defn in? [obj container]
|
|
|
|
(let [{:keys [x y w h]} obj
|
|
|
|
(let [{:keys [x y w h]} obj
|
|
|
|
{bx :x by :y bw :w bh :h} box]
|
|
|
|
{cx :x cy :y cw :w ch :h} container]
|
|
|
|
(println obj x)
|
|
|
|
|
|
|
|
(and
|
|
|
|
(and
|
|
|
|
(> x bx)
|
|
|
|
(> x cx)
|
|
|
|
(> y by)
|
|
|
|
(> y cy)
|
|
|
|
(< (+ x w) (+ bx bw))
|
|
|
|
(< (+ x w) (+ cx cw))
|
|
|
|
(< (+ y h) (+ by bh)))))
|
|
|
|
(< (+ y h) (+ cy ch)))))
|
|
|
|
|
|
|
|
|
|
|
|
(defn move [obj]
|
|
|
|
(defn moved-object [obj]
|
|
|
|
(let [{:keys [x y v d]} obj
|
|
|
|
(let [{:keys [x y v d]} obj]
|
|
|
|
moved (cond
|
|
|
|
(cond
|
|
|
|
(= d :w)
|
|
|
|
(= d :w)
|
|
|
|
(assoc obj
|
|
|
|
(assoc obj
|
|
|
|
:x (- x v))
|
|
|
|
:x (- x v))
|
|
|
@ -25,8 +24,26 @@
|
|
|
|
(= d :s)
|
|
|
|
(= d :s)
|
|
|
|
(assoc obj
|
|
|
|
(assoc obj
|
|
|
|
:y (+ y v))
|
|
|
|
:y (+ y v))
|
|
|
|
:else obj)
|
|
|
|
:else obj)))
|
|
|
|
keep-in (:keep-in obj)]
|
|
|
|
|
|
|
|
(if (or (nil? keep-in) (and keep-in (in? moved keep-in)))
|
|
|
|
(defn bump-in-wall [obj container]
|
|
|
|
|
|
|
|
(let [{:keys [x y w h d]} obj
|
|
|
|
|
|
|
|
{cx :x cy :y cw :w ch :h} container]
|
|
|
|
|
|
|
|
(case d
|
|
|
|
|
|
|
|
:w (assoc obj :x (inc cx))
|
|
|
|
|
|
|
|
:e (update obj :x #(- (+ cx cw) w 1))
|
|
|
|
|
|
|
|
:n (assoc obj :y (inc cy))
|
|
|
|
|
|
|
|
:s (update obj :y #(- (+ cy ch) h 1))
|
|
|
|
|
|
|
|
:? obj)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn move-inside [obj container]
|
|
|
|
|
|
|
|
(let [moved (moved-object obj)]
|
|
|
|
|
|
|
|
(if (in? moved container)
|
|
|
|
moved
|
|
|
|
moved
|
|
|
|
obj)))
|
|
|
|
(bump-in-wall obj container))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn move-inside-gamestate [gamestate obj]
|
|
|
|
|
|
|
|
(let [container (assoc (:dimensions gamestate)
|
|
|
|
|
|
|
|
:x 0
|
|
|
|
|
|
|
|
:y 0)]
|
|
|
|
|
|
|
|
(move-inside obj container)))
|
|
|
|