From dfe98229e3174466f19eb60145aeaeb2992be46c Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 14 Dec 2018 07:48:00 -0500 Subject: 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. --- chickadee.scm | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'chickadee.scm') 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 -- cgit v1.2.3