Rename files and improve animation code

This commit is contained in:
oakes
2013-12-30 18:35:26 -05:00
parent 5a69b2de39
commit 7f1ef44aa7
5 changed files with 49 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
(ns play-clj.core
(:require [play-clj.utils :as utils])
(:import [com.badlogic.gdx Game Gdx Input$Keys Screen]
[com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera
PerspectiveCamera Texture]
@@ -11,9 +12,9 @@
IsometricTiledMapRenderer
OrthogonalTiledMapRenderer]))
(load "2d")
(load "global")
(load "render")
(load "core_2d")
(load "core_global")
(load "core_render")
(defn find-pos
[val coll]

View File

@@ -25,18 +25,27 @@
; textures
(defn image
[^String internal-path]
(-> internal-path Texture. TextureRegion.))
[val]
(if (string? val)
(-> val Texture. TextureRegion.)
(TextureRegion. val)))
(defn split-image
([^String internal-path size]
(split-image internal-path size size))
([^String internal-path width height]
(-> internal-path image (.split width height))))
([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
[& args]
`(Animation. ~@args))
[duration images & args]
`(Animation. ~duration
(utils/into-gdx-array ~images)
(utils/static-field :graphics :g2d :Animation
~(or (first args) :normal))))
(defn get-animation-frame
([screen ^Animation animation]

View File

@@ -0,0 +1,28 @@
(ns play-clj.utils
(:require [clojure.string :as s])
(:import [com.badlogic.gdx.utils Array]))
(defn- split-keys
[key]
(-> key name (s/split #"-")))
(defn- join-keys
[keys]
(->> keys (map name) (s/join ".") (str "com.badlogic.gdx.")))
(defn static-field*
[args]
(->> (last args)
split-keys
(map s/upper-case)
(s/join "_")
(str (join-keys (butlast args)) "/")
symbol))
(defmacro static-field
[& args]
`~(static-field* args))
(defn into-gdx-array
[a]
(-> a into-array Array.))