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])
sprite-dir (if (= :? dir) player-dir dir)]
(as-> player p
(assoc p :d dir)
(assoc-in p
[:sprite :d]
sprite-dir)

@ -3,25 +3,22 @@
(defn proc-cycle [gamestate obj]
(let [sprite (:sprite obj)
sprite-cycle (:cycle sprite)
from (:from sprite-cycle)
maxpos (:count 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?
(if (> (+ last-cycle elapsed) spc)
; start cycle from new?
; reset last-cycle
(assoc-in
(if (> (inc pos) maxpos)
; restart cycle
(assoc-in obj
[:sprite :cycle :pos]
(:from sprite-cycle))
; run cycle
(update-in obj
[:sprite :cycle :pos]
inc))
[:sprite :cycle :last-cycle]
0)
(-> obj
(assoc-in
[:sprite :cycle :pos]
(if restart? from (inc pos)))
(assoc-in
[:sprite :cycle :last-cycle]
0))
(update-in obj
[:sprite :cycle :last-cycle]
#(+ % elapsed)))))

Loading…
Cancel
Save