From 1c80990156c373a87fc41c2d7dbbd030b337e41a Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Thu, 19 Oct 2017 17:57:45 +0200 Subject: [PATCH] rename objects to not collide with core functions, use case instead of cond --- src/cljs/topdown2d/core.cljs | 4 ++-- src/cljs/topdown2d/demoscene.cljs | 4 ++-- src/cljs/topdown2d/objects.cljs | 26 +++++++++++--------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/cljs/topdown2d/core.cljs b/src/cljs/topdown2d/core.cljs index 7815f53..2d0da89 100644 --- a/src/cljs/topdown2d/core.cljs +++ b/src/cljs/topdown2d/core.cljs @@ -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 {} } diff --git a/src/cljs/topdown2d/demoscene.cljs b/src/cljs/topdown2d/demoscene.cljs index f9921ee..95da4ea 100644 --- a/src/cljs/topdown2d/demoscene.cljs +++ b/src/cljs/topdown2d/demoscene.cljs @@ -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] diff --git a/src/cljs/topdown2d/objects.cljs b/src/cljs/topdown2d/objects.cljs index b8b0f45..95b9ad8 100644 --- a/src/cljs/topdown2d/objects.cljs +++ b/src/cljs/topdown2d/objects.cljs @@ -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])