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