parent
91b35cba12
commit
fe586f841a
@ -1,18 +1,32 @@
|
|||||||
(ns topdown2d.objects)
|
(ns topdown2d.objects)
|
||||||
|
|
||||||
|
(defn in? [obj box]
|
||||||
|
(let [{:keys [x y w h]} obj
|
||||||
|
{bx :x by :y bw :w bh :h} box]
|
||||||
|
(println obj x)
|
||||||
|
(and
|
||||||
|
(> x bx)
|
||||||
|
(> y by)
|
||||||
|
(< (+ x w) (+ bx bw))
|
||||||
|
(< (+ y h) (+ by bh)))))
|
||||||
|
|
||||||
(defn move [obj]
|
(defn move [obj]
|
||||||
(let [{:keys [x y v d]} obj]
|
(let [{:keys [x y v d]} obj
|
||||||
(cond
|
moved (cond
|
||||||
(= d :w)
|
(= d :w)
|
||||||
(assoc obj
|
(assoc obj
|
||||||
:x (- x v))
|
:x (- x v))
|
||||||
(= d :e)
|
(= d :e)
|
||||||
(assoc obj
|
(assoc obj
|
||||||
:x (+ x v))
|
:x (+ x v))
|
||||||
(= d :n)
|
(= d :n)
|
||||||
(assoc obj
|
(assoc obj
|
||||||
:y (- y v))
|
:y (- y v))
|
||||||
(= 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)))
|
||||||
|
moved
|
||||||
|
obj)))
|
||||||
|
Loading…
Reference in new issue