Add animation function/macro and various macros in utils

This commit is contained in:
oakes
2014-01-15 16:43:42 -05:00
parent e07486ef63
commit 8e46219778
4 changed files with 57 additions and 34 deletions

View File

@@ -74,19 +74,26 @@
[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
[duration textures & args]
`(Animation. ~duration
(u/gdx-array (map :object ~textures))
(u/static-field-upper :graphics :g2d :Animation
~(or (first args) :normal))))
[duration textures & options]
`(u/calls! ^Animation (animation* ~duration ~textures) ~@options))
(defmacro animation!
[object k & options]
`(u/call! ^Animation ~object ~k ~@options))
(defn animation->texture
([{:keys [total-time]} ^Animation animation]
(texture* (.getKeyFrame animation total-time true)))
([{:keys [total-time]} ^Animation animation is-looping?]
(texture* (.getKeyFrame animation total-time is-looping?))))
(defmacro scaling
[key]
`(u/static-field-lower :utils :Scaling ~key))

View File

@@ -36,8 +36,8 @@
`(u/calls! ^TiledMapTileLayer (tiled-map-layer* ~screen ~layer) ~@options))
(defmacro tiled-map-layer!
[layer k & options]
`(u/call! ^TiledMapTileLayer (cast TiledMapTileLayer ~layer) ~k ~@options))
[object k & options]
`(u/call! ^TiledMapTileLayer (cast TiledMapTileLayer ~object) ~k ~@options))
(defn tiled-map-cell*
[screen layer x y]
@@ -49,8 +49,8 @@
~@options))
(defmacro tiled-map-cell!
[cell k & options]
`(u/call! ^TiledMapTileLayer$Cell ~cell ~k ~@options))
[object k & options]
`(u/call! ^TiledMapTileLayer$Cell ~object ~k ~@options))
(defn ^:private refresh-renderer!
[{:keys [renderer ui-listeners]} entities]

View File

@@ -1,5 +1,6 @@
(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]))
(defn world*
@@ -8,7 +9,7 @@
([gravity-x gravity-y]
(world* gravity-x gravity-y true))
([gravity-x gravity-y sleep?]
(World. (u/gdx-vector gravity-x gravity-y) sleep?)))
(World. (m/vector gravity-x gravity-y) sleep?)))
(defmacro world
[gravity-x gravity-y & options]

View File

@@ -1,7 +1,6 @@
(ns play-clj.utils
(:require [clojure.string :as s])
(:import [com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.math Vector2 Vector3]
[com.badlogic.gdx.scenes.scene2d Actor]
[com.badlogic.gdx.utils Array ArrayMap]))
@@ -41,6 +40,8 @@
[key]
(symbol (str "." (key->camel key))))
; static fields
(defn ^:private static-field
[args transform-fn]
(->> (transform-fn (last args))
@@ -55,24 +56,9 @@
[& args]
`~(static-field args key->upper))
; data structures
(defn gdx-array
[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)))
(defmacro scaling
[key]
`(static-field-lower :utils :Scaling ~key))
; java interop
@@ -93,6 +79,35 @@
[obj & 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
(defmulti create-entity class)