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

View File

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