rename objects to not collide with core functions, use case instead of cond

master
Josha von Gizycki 7 years ago
parent 160aa92b8b
commit 1c80990156

@ -22,8 +22,8 @@
:scene :demo :scene :demo
:scenes { :scenes {
:demo { :demo {
:update demoscene/update :update demoscene/update-scene
:draw demoscene/draw :draw demoscene/draw-scene
:init demoscene/init :init demoscene/init
:data {} :data {}
} }

@ -26,7 +26,7 @@
} }
})) }))
(defn update [gamestate scenedata] (defn update-scene [gamestate scenedata]
(let [box (get-in scenedata [:data :box]) (let [box (get-in scenedata [:data :box])
bumper (get-in scenedata [:data :bumper]) bumper (get-in scenedata [:data :bumper])
dir (input/dirinput) dir (input/dirinput)
@ -42,7 +42,7 @@
(assoc :color :red)) (assoc :color :red))
(assoc mbox :color :black))))) (assoc mbox :color :black)))))
(defn draw [gamestate scenedata] (defn draw-scene [gamestate scenedata]
(let [{{:keys [bumper box]} :data} scenedata (let [{{:keys [bumper box]} :data} scenedata
ctx (:2d gamestate)] ctx (:2d gamestate)]
(let [{:keys [x y w h]} bumper] (let [{:keys [x y w h]} bumper]

@ -28,20 +28,16 @@
(defn moved-object [obj pxs] (defn moved-object [obj pxs]
(let [{:keys [x y d]} obj] (let [{:keys [x y d]} obj]
(cond (case d
(= d :w) :w (assoc obj
(assoc obj
:x (- x pxs)) :x (- x pxs))
(= d :e) :e (assoc obj
(assoc obj
:x (+ x pxs)) :x (+ x pxs))
(= d :n) :n (assoc obj
(assoc obj
:y (- y pxs)) :y (- y pxs))
(= d :s) :s (assoc obj
(assoc obj
:y (+ y pxs)) :y (+ y pxs))
:else obj))) obj)))
(defn bump-into [obj obj2] (defn bump-into [obj obj2]
(let [{:keys [x y w h d]} obj (let [{:keys [x y w h d]} obj
@ -61,7 +57,7 @@
:e (assoc obj :x (- (+ cx cw) w 1)) :e (assoc obj :x (- (+ cx cw) w 1))
:n (assoc obj :y (inc cy)) :n (assoc obj :y (inc cy))
:s (assoc obj :y (- (+ cy ch) h 1)) :s (assoc obj :y (- (+ cy ch) h 1))
:? obj))) obj)))
(defn pps->px [gamestate obj] (defn pps->px [gamestate obj]
(let [prev (get-in gamestate [:timing :prev]) (let [prev (get-in gamestate [:timing :prev])

Loading…
Cancel
Save