diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-11-30 21:14:29 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-11-30 21:14:29 -0500 |
commit | 7c60995c826a50844a961d648bca45d6f2e34233 (patch) | |
tree | d5672f59d9514873cb8a951774b1a77f7de12756 | |
parent | 5b19db7c87120e612743c609cc9f52ccb4720f10 (diff) |
examples: Update joystick example.
-rw-r--r-- | examples/joystick.scm | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/examples/joystick.scm b/examples/joystick.scm index 49e61ae..57955c9 100644 --- a/examples/joystick.scm +++ b/examples/joystick.scm @@ -21,66 +21,59 @@ ;; ;;; Code: -(use-modules - (sly game) - (sly repl) - (sly render sprite) - (sly render texture) - (sly input joystick) - (sly signal) - (sly window) - (sly vector) - (sly render font)) - -(open-window) -(start-sly-repl) -(enable-sprites) +(use-modules (sly game) + (sly signal) + (sly window) + (sly math vector) + (sly input joystick) + (sly render camera) + (sly render model) + (sly render group) + (sly render sprite) + (sly render texture) + (sly render font)) + +(load "common.scm") + (enable-joystick) (enable-fonts) -(define default-font (load-default-font)) - -(define resolution (vector 640 480)) +(define font (load-default-font 18)) -(add-hook! window-close-hook stop-game-loop) +(define resolution (vector2 640 480)) -(define p1-texture (load-texture "images/p1_front.png")) +(define player (load-sprite "images/p1_front.png")) -(define-signal p1-position - (signal-fold v+ (vector 320 240) - (signal-map - (lambda (v) - (v* (vector 8 8) v)) - (signal-sample 1 - (make-directional-signal 0 0 1))))) +(define-signal player-position + (signal-fold v+ (vector2 320 240) + (signal-map (lambda (v) (v* v 8)) + (signal-sample 1 (make-directional-signal 0 0 1))))) (define* (button-caption-signal text button #:optional (joystick 0)) - (signal-map (lambda (x) - (if x text "")) - (button-down? joystick button))) - -(define-signal p1-caption - (signal-map (lambda (text pos) - (make-label default-font - text - (v+ (vector -76 -90) pos))) + (let ((false-message (format #f "Released button ~d" button))) + (signal-map (lambda (x) (if x text false-message)) + (button-down? joystick button)))) + +(define-signal caption + (signal-map (lambda (text) + (group-move (vector2 -76 -90) + (group (label font text)))) (signal-merge + (make-signal "Press a button") (button-caption-signal "Hello there" 0) (button-caption-signal "Thanks for pressing button 1" 1) (button-caption-signal "This is the other caption" 2) - (button-caption-signal "This is the other other caption" 3)) - p1-position)) + (button-caption-signal "This is the other other caption" 3)))) -(define (draw-p1-caption dt alpha) - (draw-label (signal-ref p1-caption))) +(define-signal scene + (signal-map (lambda (position caption) + (group-move position + (group player caption))) + player-position caption)) -(define (draw-p1 dt alpha) - (draw-sprite (make-sprite p1-texture - #:position (signal-ref p1-position)))) +(define camera (orthographic-camera (vx resolution) (vy resolution))) -(add-hook! draw-hook draw-p1) - -(add-hook! draw-hook draw-p1-caption) +(add-hook! draw-hook (lambda _ (draw-group (signal-ref scene) camera))) (add-hook! joystick-axis-hook (lambda (which axis value) @@ -100,3 +93,7 @@ (with-window (make-window #:title "Joystick test" #:resolution resolution) (start-game-loop)) + +;;; Local Variables: +;;; compile-command: "../pre-inst-env guile joystick.scm" +;;; End: |