diff --git a/src/cljs/topdown2d/demoscene.cljs b/src/cljs/topdown2d/demoscene.cljs index 9e6b192..d9e6840 100644 --- a/src/cljs/topdown2d/demoscene.cljs +++ b/src/cljs/topdown2d/demoscene.cljs @@ -31,24 +31,31 @@ :count 8 :from 1 :pos 0 + :last-cycle 0 ; seconds per cycle :spc 0.08 - :last-cycle 0 } } } })) +(defn update-player [gamestate player dir] + (let [player-dir (get-in player [:sprite :d]) + sprite-dir (if (= :? dir) player-dir dir)] + (as-> player p + (assoc-in p + [:sprite :d] + sprite-dir) + (if-not (= :? dir) + (sprites/proc-cycle gamestate p) + p)))) + (defn update-scene [gamestate scenedata] (let [player (get-in scenedata [:data :player]) - dir (input/dirinput :?) - player (assoc-in player - [:sprite :d] - dir) - player (sprites/proc-cycle gamestate player)] + dir (input/dirinput)] (assoc-in scenedata [:data :player] - player))) + (update-player gamestate player dir)))) (defn draw-scene [gamestate scenedata] (let [{{:keys [bumper player]} :data} scenedata diff --git a/src/cljs/topdown2d/input.cljs b/src/cljs/topdown2d/input.cljs index 13ad099..9d06b88 100644 --- a/src/cljs/topdown2d/input.cljs +++ b/src/cljs/topdown2d/input.cljs @@ -18,10 +18,10 @@ #(assoc % (.-code event) false)) false)) -(defn dirinput [defdir] +(defn dirinput [] (cond (keydown? :ArrowLeft) :w (keydown? :ArrowRight) :e (keydown? :ArrowUp) :n (keydown? :ArrowDown) :s - :else defdir)) + :else :?))