player keeps direction and stops walking

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

@ -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

@ -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 :?))

Loading…
Cancel
Save