From 5a69b2de390d0e76c84ee53c1ad0732fd959ce0e Mon Sep 17 00:00:00 2001 From: oakes Date: Mon, 30 Dec 2013 02:25:55 -0500 Subject: [PATCH] Remove platform-specific defgame --- android/src/play_clj/native.clj | 7 +------ common/src/play_clj/core.clj | 6 +++++- common/src/play_clj/global.clj | 16 +--------------- desktop/src/play_clj/native.clj | 18 +----------------- ios/src/play_clj/native.clj | 7 +------ 5 files changed, 9 insertions(+), 45 deletions(-) diff --git a/android/src/play_clj/native.clj b/android/src/play_clj/native.clj index b546a92..b47346f 100644 --- a/android/src/play_clj/native.clj +++ b/android/src/play_clj/native.clj @@ -1,6 +1 @@ -(ns play-clj.native - (:require [play-clj.core :refer :all])) - -(defmacro defgame - [name & {:keys [] :as options}] - `(def ~name (create-game ~options))) +(ns play-clj.native) diff --git a/common/src/play_clj/core.clj b/common/src/play_clj/core.clj index 4f8cfe2..108e881 100644 --- a/common/src/play_clj/core.clj +++ b/common/src/play_clj/core.clj @@ -91,7 +91,11 @@ [^Game game ^Screen screen] (.setScreen game screen)) -(defn create-game +(defn defgame* [{:keys [start-screen]}] (proxy [Game] [] (create [] (when start-screen (set-screen! this start-screen))))) + +(defmacro defgame + [name & {:keys [] :as options}] + `(def ~name (defgame* ~options))) diff --git a/common/src/play_clj/global.clj b/common/src/play_clj/global.clj index c1751e9..c26e39f 100644 --- a/common/src/play_clj/global.clj +++ b/common/src/play_clj/global.clj @@ -15,6 +15,7 @@ :width `(.getWidth (Gdx/graphics)) :height `(.getHeight (Gdx/graphics)) :is-fullscreen? `(.isFullscreen (Gdx/graphics)) + :is-touched? `(.isTouched (Gdx/input)) :x `(.getX (Gdx/input)) :y `(.getY (Gdx/input)) nil)) @@ -36,21 +37,6 @@ nil) key)) -(defn resolve-touch - [key] - (case key - :down `(> (game :y) (* (game :height) (/ 2 3))) - :up `(< (game :y) (/ (game :height) 3)) - :left `(< (game :x) (/ (game :width) 3)) - :right `(> (game :x) (* (game :width) (/ 2 3))) - false)) - (defmacro is-pressed? [key] `(.isKeyPressed (Gdx/input) ~(resolve-key key))) - -(defmacro is-touched? - ([] - `(.isTouched (Gdx/input))) - ([key] - `(and (is-touched?) ~(resolve-touch key)))) diff --git a/desktop/src/play_clj/native.clj b/desktop/src/play_clj/native.clj index 70aece3..b47346f 100644 --- a/desktop/src/play_clj/native.clj +++ b/desktop/src/play_clj/native.clj @@ -1,17 +1 @@ -(ns play-clj.native - (:require [play-clj.core :refer :all]) - (:import [com.badlogic.gdx.backends.lwjgl LwjglApplication] - [org.lwjgl.input Keyboard])) - -(defmacro defgame - [name & {:keys [title width height] - :as options}] - (let [title (or title "") - width (or width 800) - height (or height 600)] - `(do - (def ~name (create-game ~options)) - (defn ~'-main - [] - (LwjglApplication. ~name ~title ~width ~height true) - (Keyboard/enableRepeatEvents true))))) +(ns play-clj.native) diff --git a/ios/src/play_clj/native.clj b/ios/src/play_clj/native.clj index b546a92..b47346f 100644 --- a/ios/src/play_clj/native.clj +++ b/ios/src/play_clj/native.clj @@ -1,6 +1 @@ -(ns play-clj.native - (:require [play-clj.core :refer :all])) - -(defmacro defgame - [name & {:keys [] :as options}] - `(def ~name (create-game ~options))) +(ns play-clj.native)