From 278f0958dd381922e59254cdb0403d74738fbe62 Mon Sep 17 00:00:00 2001
From: Gene Pasquet <dev@etenil.net>
Date: Sat, 18 May 2024 15:41:44 +0100
Subject: Make player move!

---
 turbo.scm | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/turbo.scm b/turbo.scm
index 0430900..19ad423 100644
--- a/turbo.scm
+++ b/turbo.scm
@@ -41,17 +41,29 @@
 (define car-pos-x 0.0)
 (define car-speed 4.0)
 (define car-steering 4.0)
+(define player-velocity (vec2 0 0))
 
-(define player-initial-position
+(define player-position
   (vec2 (/ (- (window-width (current-window)) vehicle-length) 2)
 	(+ (lane-y 3)
 	   (/ (- lane-height vehicle-height) 2))))
 
 (define (draw alpha)
-  ;; Draw the road
   (draw-road 0 road-start-y 5)
 
   (draw-text "Turbo Racers!" (vec2 260.0 (- (window-height (current-window)) 25)))
 
-  (draw-sprite the-car player-initial-position)
+  (set! player-position (vec2+ player-position player-velocity))
+
+  (draw-sprite the-car player-position)
   )
+
+(define (key-press key modifiers repeat?)
+  (if (eq? key 'w)
+      (set! player-velocity (vec2 0 car-steering)))
+  (if (eq? key 's)
+      (set! player-velocity (vec2 0 (* car-steering -1)))))
+
+(define (key-release key modifiers)
+  (if (or (eq? key 'w) (eq? key 's))
+      (set! player-velocity (vec2 0 0))))
-- 
cgit v1.2.3