code cleanup

master
Josha von Gizycki 7 years ago
parent 4988bf7d75
commit 6f7050e887

@ -48,6 +48,7 @@
(let [player-dir (get-in player [:sprite :d]) (let [player-dir (get-in player [:sprite :d])
sprite-dir (if (= :? dir) player-dir dir)] sprite-dir (if (= :? dir) player-dir dir)]
(as-> player p (as-> player p
(assoc p :d dir)
(assoc-in p (assoc-in p
[:sprite :d] [:sprite :d]
sprite-dir) sprite-dir)

@ -3,25 +3,22 @@
(defn proc-cycle [gamestate obj] (defn proc-cycle [gamestate obj]
(let [sprite (:sprite obj) (let [sprite (:sprite obj)
sprite-cycle (:cycle sprite) sprite-cycle (:cycle sprite)
from (:from sprite-cycle)
maxpos (:count sprite-cycle) maxpos (:count sprite-cycle)
{:keys [pos spc last-cycle]} sprite-cycle {:keys [pos spc last-cycle]} sprite-cycle
elapsed (get-in gamestate [:timing :elapsed])] elapsed (get-in gamestate [:timing :elapsed])
restart? (> (inc pos) maxpos)]
; new sprite frame? ; new sprite frame?
(if (> (+ last-cycle elapsed) spc) (if (> (+ last-cycle elapsed) spc)
; start cycle from new? ; start cycle from new?
; reset last-cycle ; reset last-cycle
(assoc-in (-> obj
(if (> (inc pos) maxpos) (assoc-in
; restart cycle [:sprite :cycle :pos]
(assoc-in obj (if restart? from (inc pos)))
[:sprite :cycle :pos] (assoc-in
(:from sprite-cycle)) [:sprite :cycle :last-cycle]
; run cycle 0))
(update-in obj
[:sprite :cycle :pos]
inc))
[:sprite :cycle :last-cycle]
0)
(update-in obj (update-in obj
[:sprite :cycle :last-cycle] [:sprite :cycle :last-cycle]
#(+ % elapsed))))) #(+ % elapsed)))))

Loading…
Cancel
Save