Remove platform-specific projects
This commit is contained in:
57
src/play_clj/core_2d.clj
Normal file
57
src/play_clj/core_2d.clj
Normal file
@@ -0,0 +1,57 @@
|
||||
(in-ns 'play-clj.core)
|
||||
|
||||
; drawing
|
||||
|
||||
(defmulti sprite-batch #(-> % :renderer class) :default nil)
|
||||
|
||||
(defmethod sprite-batch nil [screen]
|
||||
(SpriteBatch.))
|
||||
|
||||
(defmethod sprite-batch BatchTiledMapRenderer [{:keys [renderer]}]
|
||||
(assert renderer)
|
||||
(.getSpriteBatch renderer))
|
||||
|
||||
(defn draw! [{:keys [renderer]} entities]
|
||||
(assert renderer)
|
||||
(let [batch (.getSpriteBatch renderer)]
|
||||
(.begin batch)
|
||||
(doseq [e entities]
|
||||
(cond
|
||||
(map? e)
|
||||
(let [{:keys [image x y width height]} e]
|
||||
(.draw batch image (float x) (float y) (float width) (float height)))
|
||||
(isa? (type e) Actor)
|
||||
(.draw e batch 1)))
|
||||
(.end batch))
|
||||
entities)
|
||||
|
||||
; textures
|
||||
|
||||
(defn image
|
||||
[val]
|
||||
(if (string? val)
|
||||
(-> val Texture. TextureRegion.)
|
||||
(TextureRegion. val)))
|
||||
|
||||
(defn split-image
|
||||
([val size]
|
||||
(split-image val size size))
|
||||
([val width height]
|
||||
(-> val image (.split width height))))
|
||||
|
||||
(defn flip-image
|
||||
[val x? y?]
|
||||
(doto (image val) (.flip x? y?)))
|
||||
|
||||
(defmacro animation
|
||||
[duration images & args]
|
||||
`(Animation. ~duration
|
||||
(utils/gdx-into-array ~images)
|
||||
(utils/gdx-static-field :graphics :g2d :Animation
|
||||
~(or (first args) :normal))))
|
||||
|
||||
(defn get-key-frame
|
||||
([screen ^Animation animation]
|
||||
(.getKeyFrame animation (:total-time screen) true))
|
||||
([screen ^Animation animation is-looping?]
|
||||
(.getKeyFrame animation (:total-time screen) is-looping?)))
|
||||
Reference in New Issue
Block a user