|
|
|
@ -6,8 +6,8 @@
|
|
|
|
|
from (:from sprite-cycle)
|
|
|
|
|
maxpos (:count sprite-cycle)
|
|
|
|
|
{:keys [pos spc last-cycle]} sprite-cycle
|
|
|
|
|
elapsed (get-in gamestate [:timing :elapsed])
|
|
|
|
|
restart? (> (inc pos) maxpos)]
|
|
|
|
|
restart? (> (inc pos) maxpos)
|
|
|
|
|
elapsed (get-in gamestate [:timing :elapsed])]
|
|
|
|
|
; new sprite frame?
|
|
|
|
|
(if (> (+ last-cycle elapsed) spc)
|
|
|
|
|
; start cycle from new?
|
|
|
|
@ -23,19 +23,24 @@
|
|
|
|
|
[:sprite :cycle :last-cycle]
|
|
|
|
|
#(+ % elapsed)))))
|
|
|
|
|
|
|
|
|
|
(defn pos-in-sprite [sprite]
|
|
|
|
|
(let [{:keys [d size rows]} sprite
|
|
|
|
|
(defn reset-cycle [obj]
|
|
|
|
|
(assoc-in
|
|
|
|
|
obj
|
|
|
|
|
[:sprite :cycle :pos]
|
|
|
|
|
0))
|
|
|
|
|
|
|
|
|
|
(defn pos-in-sprite [sprite d]
|
|
|
|
|
(let [{:keys [size rows]} sprite
|
|
|
|
|
pos (get-in sprite [:cycle :pos])
|
|
|
|
|
row (d rows)]
|
|
|
|
|
{:y (* row size) :x (* pos size)}))
|
|
|
|
|
|
|
|
|
|
(defn draw [gamestate obj]
|
|
|
|
|
(defn draw [ctx obj]
|
|
|
|
|
(let [{:keys [x y w h d sprite]} obj
|
|
|
|
|
image (:image sprite)
|
|
|
|
|
sprite-size (:size sprite)
|
|
|
|
|
{:keys [ctx]} gamestate
|
|
|
|
|
sprite-cycle (:cycle sprite)
|
|
|
|
|
pos (pos-in-sprite sprite)]
|
|
|
|
|
pos (pos-in-sprite sprite d)]
|
|
|
|
|
(.drawImage ctx
|
|
|
|
|
image
|
|
|
|
|
(:x pos) (:y pos) sprite-size sprite-size
|
|
|
|
|