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
:scenes {
:demo {
:update demoscene/update
:draw demoscene/draw
:update demoscene/update-scene
:draw demoscene/draw-scene
:init demoscene/init
:data {}
}

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

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

Loading…
Cancel
Save