Remove platform-specific defgame

This commit is contained in:
oakes
2013-12-30 02:25:55 -05:00
parent df7ca4f1d4
commit 5a69b2de39
5 changed files with 9 additions and 45 deletions

View File

@@ -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)

View File

@@ -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)))

View File

@@ -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))))

View File

@@ -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)

View File

@@ -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)