Rename files and improve animation code
This commit is contained in:
@@ -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]
|
||||||
|
|||||||
@@ -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]
|
||||||
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