summaryrefslogtreecommitdiff
path: root/heyllama.scm
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-09-19 22:19:01 +0200
committerThomas White <taw@physics.org>2020-09-19 22:19:01 +0200
commit62027ba25490f15acfc01fb3efdafea5cb9a1ba6 (patch)
tree239ff78563b101835174f8e33c34438051fd2722 /heyllama.scm
parent9504dfe8aeb2f98545a225bb60e776672cf3ebf6 (diff)
Use key-pressed? instead of key press/release handlers
Diffstat (limited to 'heyllama.scm')
-rw-r--r--heyllama.scm33
1 files changed, 16 insertions, 17 deletions
diff --git a/heyllama.scm b/heyllama.scm
index c3a325f..885918a 100644
--- a/heyllama.scm
+++ b/heyllama.scm
@@ -49,14 +49,6 @@
(define (update-animal animal tstep)
- (let ((wd (get-walk-direction animal)))
- (unless (eq? wd 0)
- (set-face-direction! animal wd)
- (vec2-add! (get-pos animal) #v((* tstep wd 0.2) 0))
- (set-animation-step! animal
- (floor-remainder
- (+ (get-animation-step animal) wd)
- 16))))
(vec2-add! (get-pos animal) (get-vel animal))
(if (> (vec2-y (get-pos animal)) 200.0)
(set-vel! animal
@@ -119,6 +111,22 @@
(update-animal llama tstep)
+ (when (key-pressed? 'right)
+ (set-face-direction! llama 1)
+ (vec2-add! (get-pos llama) #v((* tstep 0.2) 0))
+ (set-animation-step! llama
+ (floor-remainder
+ (+ (get-animation-step llama) 1)
+ 16)))
+
+ (when (key-pressed? 'left)
+ (set-face-direction! llama -1)
+ (vec2-add! (get-pos llama) #v((* tstep -0.2) 0))
+ (set-animation-step! llama
+ (floor-remainder
+ (- (get-animation-step llama) 1)
+ 16)))
+
;; Ensure llama is near centre of screen
(let ((fovea (make-rect 150.0 150.0 350.0 350.0))
(llama-rect (get-screen-rect llama)))
@@ -129,22 +137,13 @@
(define (key-press key scancode modifier repeat?)
(case key
((q) (abort-game))
- ((right) (set-walk-direction! llama 1))
- ((left) (set-walk-direction! llama -1))
((space) (unless repeat?
(set-vel! llama #v(0.0 15.0))))))
-(define (key-release key scancode modifier)
- (case key
- ((right) (set-walk-direction! llama 0))
- ((left) (set-walk-direction! llama 0))))
-
-
(run-game #:window-title "Hey Llama!"
#:load load
#:draw draw
#:key-press key-press
#:update-hz 60
- #:key-release key-release
#:update update)