Add controller query procedures.
authorDavid Thompson <dthompson2@worcester.edu>
Fri, 14 Dec 2018 12:48:00 +0000 (07:48 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Fri, 14 Dec 2018 12:48:00 +0000 (07:48 -0500)
Not ready to document them at this time since I have not done full
tests with a USB controller yet.

* chickadee.scm (controller-button-pressed?, controller-axis): New procedures.

chickadee.scm

index 9e230a3..9b225ba 100644 (file)
   #:use-module (chickadee render gl)
   #:use-module (chickadee render gpu)
   #:use-module (chickadee render viewport)
-  #:export (mouse-x
+  #:export (current-window
+            controller-button-pressed?
+            controller-axis
+            key-pressed?
+            key-released?
+            mouse-x
             mouse-y
             mouse-button-pressed?
             mouse-button-released?
-            key-pressed?
-            key-released?
-            current-window
             run-game)
   #:re-export (abort-game))
 
         (add-controller i))
       (loop (+ i 1)))))
 
+(define (controller-button-pressed? controller button)
+  "Return #t if BUTTON is currently being pressed on CONTROLLER."
+  (sdl2:game-controller-button-pressed? controller button))
+
+(define (controller-axis controller axis)
+  "Return a floating point value in the range [-1, 1] corresponding to
+how much AXIS is being pushed on CONTROLLER.  0 is returned if AXIS is
+not being pushed at all."
+  (- (/ (sdl2:game-controller-axis controller axis)
+        32768.0)
+     0.5))
+
 (define current-window (make-parameter #f))
 
 (define* (run-game #:key