player keeps direction and stops walking

master
Josha von Gizycki 7 years ago
parent 6c5cc517a1
commit e4d5e7c9b7

@ -31,24 +31,31 @@
:count 8 :count 8
:from 1 :from 1
:pos 0 :pos 0
:last-cycle 0
; seconds per cycle ; seconds per cycle
:spc 0.08 :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] (defn update-scene [gamestate scenedata]
(let [player (get-in scenedata [:data :player]) (let [player (get-in scenedata [:data :player])
dir (input/dirinput :?) dir (input/dirinput)]
player (assoc-in player
[:sprite :d]
dir)
player (sprites/proc-cycle gamestate player)]
(assoc-in scenedata (assoc-in scenedata
[:data :player] [:data :player]
player))) (update-player gamestate player dir))))
(defn draw-scene [gamestate scenedata] (defn draw-scene [gamestate scenedata]
(let [{{:keys [bumper player]} :data} scenedata (let [{{:keys [bumper player]} :data} scenedata

@ -18,10 +18,10 @@
#(assoc % (.-code event) false)) #(assoc % (.-code event) false))
false)) false))
(defn dirinput [defdir] (defn dirinput []
(cond (cond
(keydown? :ArrowLeft) :w (keydown? :ArrowLeft) :w
(keydown? :ArrowRight) :e (keydown? :ArrowRight) :e
(keydown? :ArrowUp) :n (keydown? :ArrowUp) :n
(keydown? :ArrowDown) :s (keydown? :ArrowDown) :s
:else defdir)) :else :?))

Loading…
Cancel
Save