Last active
November 13, 2016 19:30
-
-
Save spacepluk/ac2e6d578a1223f65b2eb918bd5b5c0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/input.clj b/input.clj | |
| index 8b6089d..87ca39a 100644 | |
| --- a/input.clj | |
| +++ b/input.clj | |
| @@ -1,16 +1,16 @@ | |
| (ns hard.input | |
| (:import | |
| [UnityEngine Input KeyCode Camera Physics Time Camera])) | |
| - | |
| + | |
| (def ^:private axis-cache (atom [0 0])) | |
| (declare mouse?) | |
| - | |
| + | |
| (defn get-keycode [s] | |
| (try (or (eval (symbol (str "KeyCode/" s))) false) (catch Exception e nil))) | |
| (defn ^:private kcode* [k] | |
| - (cond | |
| + (cond | |
| (keyword? k) (apply str (rest (str k))) | |
| (symbol? k) (get-keycode k) | |
| (string? k) k)) | |
| @@ -24,6 +24,15 @@ | |
| (defn key-up? [k] | |
| (Input/GetKeyUp (kcode* k))) | |
| +(defn button? [s] | |
| + (Input/GetButton s)) | |
| + | |
| +(defn button-up? [s] | |
| + (Input/GetButtonUp s)) | |
| + | |
| +(defn button-down? [s] | |
| + (Input/GetButtonDown s)) | |
| + | |
| (defmacro route [f & more] | |
| (let [pairs (partition 2 more)] | |
| (cons 'do | |
| @@ -36,16 +45,16 @@ | |
| (cond (#{0 1 2} b) b | |
| :else (or (get {:left 0 :middle 1 :right 2} b) 0))) | |
| -(defn mouse-down? | |
| - ([] (mouse-down? 0)) | |
| +(defn mouse-down? | |
| + ([] (mouse-down? 0)) | |
| ([b] (Input/GetMouseButtonDown (mouse-code* b)))) | |
| -(defn mouse-up? | |
| - ([] (mouse-up? 0)) | |
| +(defn mouse-up? | |
| + ([] (mouse-up? 0)) | |
| ([b] (Input/GetMouseButtonUp (mouse-code* b)))) | |
| -(defn mouse? | |
| - ([] (mouse? 0)) | |
| +(defn mouse? | |
| + ([] (mouse? 0)) | |
| ([b] (Input/GetMouseButton (mouse-code* b)))) | |
| @@ -80,42 +89,21 @@ | |
| (let [hit (RaycastHit.)] | |
| (Physics/RaycastAll (.origin ray) (.direction ray) length)))) | |
| - | |
| + | |
| (defn joy [] | |
| [(get-axis :horizontal) | |
| (get-axis :vertical)]) | |
| (defn joy-left? [] | |
| - (let [h (get-axis :horizontal) | |
| - oh (first @axis-cache)] | |
| - (if (and (< h -0.3) (> oh -0.3)) | |
| - (do (swap! axis-cache #(identity [h (last %)])) | |
| - true) | |
| - false))) | |
| + (< (get-axis :horizontal) -0.3)) | |
| (defn joy-right? [] | |
| - (let [h (get-axis :horizontal) | |
| - oh (first @axis-cache)] | |
| - (if (and (> h 0.3) (< oh 0.3)) | |
| - (do (swap! axis-cache #(identity [h (last %)])) | |
| - true) | |
| - false))) | |
| + (> (get-axis :horizontal) 0.3)) | |
| (defn joy-up? [] | |
| - (let [v (get-axis :vertical) | |
| - ov (last @axis-cache)] | |
| - | |
| - (if (and (< v -0.3) (> ov -0.3)) | |
| - (do (swap! axis-cache #(identity [(first %) v])) | |
| - true) | |
| - false))) | |
| + (> (get-axis :vertical) 0.3)) | |
| (defn joy-down? [] | |
| - (let [v (get-axis :vertical) | |
| - ov (last @axis-cache)] | |
| - (if (and (> v 0.3) (< ov 0.3)) | |
| - (do (swap! axis-cache #(identity [(first %) v])) | |
| - true) | |
| - false))) | |
| + (< (get-axis :vertical) -0.3)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment