Add animation function/macro and various macros in utils
This commit is contained in:
@@ -74,19 +74,26 @@
|
|||||||
[entity k & options]
|
[entity k & options]
|
||||||
`(u/call! ^TextureRegion (:object ~entity) ~k ~@options))
|
`(u/call! ^TextureRegion (:object ~entity) ~k ~@options))
|
||||||
|
|
||||||
|
(defmacro play-mode
|
||||||
|
[key]
|
||||||
|
`(u/static-field-upper :graphics :g2d :Animation ~key))
|
||||||
|
|
||||||
|
(defn animation*
|
||||||
|
[duration textures]
|
||||||
|
(Animation. duration
|
||||||
|
(u/gdx-array (map :object textures))
|
||||||
|
(play-mode :normal)))
|
||||||
|
|
||||||
(defmacro animation
|
(defmacro animation
|
||||||
[duration textures & args]
|
[duration textures & options]
|
||||||
`(Animation. ~duration
|
`(u/calls! ^Animation (animation* ~duration ~textures) ~@options))
|
||||||
(u/gdx-array (map :object ~textures))
|
|
||||||
(u/static-field-upper :graphics :g2d :Animation
|
(defmacro animation!
|
||||||
~(or (first args) :normal))))
|
[object k & options]
|
||||||
|
`(u/call! ^Animation ~object ~k ~@options))
|
||||||
|
|
||||||
(defn animation->texture
|
(defn animation->texture
|
||||||
([{:keys [total-time]} ^Animation animation]
|
([{:keys [total-time]} ^Animation animation]
|
||||||
(texture* (.getKeyFrame animation total-time true)))
|
(texture* (.getKeyFrame animation total-time true)))
|
||||||
([{:keys [total-time]} ^Animation animation is-looping?]
|
([{:keys [total-time]} ^Animation animation is-looping?]
|
||||||
(texture* (.getKeyFrame animation total-time is-looping?))))
|
(texture* (.getKeyFrame animation total-time is-looping?))))
|
||||||
|
|
||||||
(defmacro scaling
|
|
||||||
[key]
|
|
||||||
`(u/static-field-lower :utils :Scaling ~key))
|
|
||||||
|
|||||||
@@ -36,8 +36,8 @@
|
|||||||
`(u/calls! ^TiledMapTileLayer (tiled-map-layer* ~screen ~layer) ~@options))
|
`(u/calls! ^TiledMapTileLayer (tiled-map-layer* ~screen ~layer) ~@options))
|
||||||
|
|
||||||
(defmacro tiled-map-layer!
|
(defmacro tiled-map-layer!
|
||||||
[layer k & options]
|
[object k & options]
|
||||||
`(u/call! ^TiledMapTileLayer (cast TiledMapTileLayer ~layer) ~k ~@options))
|
`(u/call! ^TiledMapTileLayer (cast TiledMapTileLayer ~object) ~k ~@options))
|
||||||
|
|
||||||
(defn tiled-map-cell*
|
(defn tiled-map-cell*
|
||||||
[screen layer x y]
|
[screen layer x y]
|
||||||
@@ -49,8 +49,8 @@
|
|||||||
~@options))
|
~@options))
|
||||||
|
|
||||||
(defmacro tiled-map-cell!
|
(defmacro tiled-map-cell!
|
||||||
[cell k & options]
|
[object k & options]
|
||||||
`(u/call! ^TiledMapTileLayer$Cell ~cell ~k ~@options))
|
`(u/call! ^TiledMapTileLayer$Cell ~object ~k ~@options))
|
||||||
|
|
||||||
(defn ^:private refresh-renderer!
|
(defn ^:private refresh-renderer!
|
||||||
[{:keys [renderer ui-listeners]} entities]
|
[{:keys [renderer ui-listeners]} entities]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
(ns play-clj.physics
|
(ns play-clj.physics
|
||||||
(:require [play-clj.utils :as u])
|
(:require [play-clj.math :as m]
|
||||||
|
[play-clj.utils :as u])
|
||||||
(:import [com.badlogic.gdx.physics.box2d World]))
|
(:import [com.badlogic.gdx.physics.box2d World]))
|
||||||
|
|
||||||
(defn world*
|
(defn world*
|
||||||
@@ -8,7 +9,7 @@
|
|||||||
([gravity-x gravity-y]
|
([gravity-x gravity-y]
|
||||||
(world* gravity-x gravity-y true))
|
(world* gravity-x gravity-y true))
|
||||||
([gravity-x gravity-y sleep?]
|
([gravity-x gravity-y sleep?]
|
||||||
(World. (u/gdx-vector gravity-x gravity-y) sleep?)))
|
(World. (m/vector gravity-x gravity-y) sleep?)))
|
||||||
|
|
||||||
(defmacro world
|
(defmacro world
|
||||||
[gravity-x gravity-y & options]
|
[gravity-x gravity-y & options]
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
(ns play-clj.utils
|
(ns play-clj.utils
|
||||||
(:require [clojure.string :as s])
|
(:require [clojure.string :as s])
|
||||||
(:import [com.badlogic.gdx.graphics.g2d TextureRegion]
|
(:import [com.badlogic.gdx.graphics.g2d TextureRegion]
|
||||||
[com.badlogic.gdx.math Vector2 Vector3]
|
|
||||||
[com.badlogic.gdx.scenes.scene2d Actor]
|
[com.badlogic.gdx.scenes.scene2d Actor]
|
||||||
[com.badlogic.gdx.utils Array ArrayMap]))
|
[com.badlogic.gdx.utils Array ArrayMap]))
|
||||||
|
|
||||||
@@ -41,6 +40,8 @@
|
|||||||
[key]
|
[key]
|
||||||
(symbol (str "." (key->camel key))))
|
(symbol (str "." (key->camel key))))
|
||||||
|
|
||||||
|
; static fields
|
||||||
|
|
||||||
(defn ^:private static-field
|
(defn ^:private static-field
|
||||||
[args transform-fn]
|
[args transform-fn]
|
||||||
(->> (transform-fn (last args))
|
(->> (transform-fn (last args))
|
||||||
@@ -55,24 +56,9 @@
|
|||||||
[& args]
|
[& args]
|
||||||
`~(static-field args key->upper))
|
`~(static-field args key->upper))
|
||||||
|
|
||||||
; data structures
|
(defmacro scaling
|
||||||
|
[key]
|
||||||
(defn gdx-array
|
`(static-field-lower :utils :Scaling ~key))
|
||||||
[arr]
|
|
||||||
(Array. true (into-array arr) 1 (count arr)))
|
|
||||||
|
|
||||||
(defn gdx-array-map
|
|
||||||
[hmap]
|
|
||||||
(let [amap (ArrayMap.)]
|
|
||||||
(doseq [[k v] hmap]
|
|
||||||
(.put amap k v))
|
|
||||||
amap))
|
|
||||||
|
|
||||||
(defn gdx-vector
|
|
||||||
([x y]
|
|
||||||
(Vector2. x y))
|
|
||||||
([x y z]
|
|
||||||
(Vector3. x y z)))
|
|
||||||
|
|
||||||
; java interop
|
; java interop
|
||||||
|
|
||||||
@@ -93,6 +79,35 @@
|
|||||||
[obj & args]
|
[obj & args]
|
||||||
`(doto ~obj ~@(create-method-calls [] args)))
|
`(doto ~obj ~@(create-method-calls [] args)))
|
||||||
|
|
||||||
|
; data structures
|
||||||
|
|
||||||
|
(defn gdx-array*
|
||||||
|
[clj-arr]
|
||||||
|
(Array. true (into-array clj-arr) 1 (count clj-arr)))
|
||||||
|
|
||||||
|
(defmacro gdx-array
|
||||||
|
[clj-arr & options]
|
||||||
|
`(calls! ^Array (gdx-array* ~clj-arr) ~@options))
|
||||||
|
|
||||||
|
(defmacro gdx-array!
|
||||||
|
[object k & options]
|
||||||
|
`(call! ^Array ~object ~k ~@options))
|
||||||
|
|
||||||
|
(defn gdx-array-map*
|
||||||
|
[clj-map]
|
||||||
|
(let [gdx-map (ArrayMap.)]
|
||||||
|
(doseq [[k v] clj-map]
|
||||||
|
(.put gdx-map k v))
|
||||||
|
gdx-map))
|
||||||
|
|
||||||
|
(defmacro gdx-array-map
|
||||||
|
[clj-map & options]
|
||||||
|
`(calls! ^ArrayMap (gdx-array-map* ~clj-map) ~@options))
|
||||||
|
|
||||||
|
(defmacro gdx-array-map!
|
||||||
|
[object k & options]
|
||||||
|
`(call! ^ArrayMap ~object ~k ~@options))
|
||||||
|
|
||||||
; entities
|
; entities
|
||||||
|
|
||||||
(defmulti create-entity class)
|
(defmulti create-entity class)
|
||||||
|
|||||||
Reference in New Issue
Block a user