summaryrefslogtreecommitdiff
path: root/chickadee.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-12-14 07:48:00 -0500
committerDavid Thompson <dthompson2@worcester.edu>2018-12-14 07:48:00 -0500
commitdfe98229e3174466f19eb60145aeaeb2992be46c (patch)
tree6e52e013da8017fc699bfdd25cffe214249f8d7a /chickadee.scm
parentf822c3137a906f6bfe83243656c229bb085f98b4 (diff)
Add controller query procedures.
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.
Diffstat (limited to 'chickadee.scm')
-rw-r--r--chickadee.scm22
1 files changed, 18 insertions, 4 deletions
diff --git a/chickadee.scm b/chickadee.scm
index 9e230a3..9b225ba 100644
--- a/chickadee.scm
+++ b/chickadee.scm
@@ -38,13 +38,15 @@
#: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))
@@ -95,6 +97,18 @@
(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