Rename files and improve animation code
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
28
common/src/play_clj/utils.clj
Normal file
28
common/src/play_clj/utils.clj
Normal 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.))
|
||||
Reference in New Issue
Block a user