From 4574952982cf2f1c0a81edafa74cc37abb161759 Mon Sep 17 00:00:00 2001
From: Gene Pasquet <dev@etenil.net>
Date: Sun, 19 May 2024 09:45:36 +0100
Subject: Code tidy up

---
 turbo.scm | 69 +++++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 41 insertions(+), 28 deletions(-)

diff --git a/turbo.scm b/turbo.scm
index 367b03c..db4a8ba 100644
--- a/turbo.scm
+++ b/turbo.scm
@@ -4,13 +4,31 @@
 	     (ice-9 pretty-print)
 	     (ice-9 format))
 
+;;;; Constants and variables
+
 (define lane-height 65)
 (define lane-length 200)
+(define road-start-y 80)
+(define road-section-position 0)
 (define road (load-tileset "road.png" lane-length lane-height))
 (define road-top (texture-atlas-ref road 2))
 (define road-bottom (texture-atlas-ref road 0))
 (define road-lane (texture-atlas-ref road 1))
-(define road-start-y 80)
+
+(define vehicle-height 45)
+(define vehicle-length 100)
+(define vehicle-steering-speed 4.0)
+(define vehicles (load-tileset "vehicles.png" vehicle-length vehicle-height))
+
+(define player-car (texture-atlas-ref vehicles 0))
+(define player-velocity (vec2 0 0))
+(define player-min-speed 4)
+(define player-max-speed 20)
+(define player-speed player-min-speed)
+
+(define load-complete #f)
+
+;;;; Game functions
 
 (define (draw-lanes x y num-lanes)
   (if (> num-lanes 0)
@@ -33,47 +51,42 @@
   (+ road-start-y
      (* lane-height (- num-lane 1))))
 
-(define vehicle-height 45)
-(define vehicle-length 100)
-(define vehicles (load-tileset "vehicles.png" vehicle-length vehicle-height))
-(define selected-car (texture-atlas-ref vehicles 0))
-
-(define car-pos-x 0.0)
-(define car-steering-speed 4.0)
-(define player-velocity (vec2 0 0))
-(define road-min-speed 4)
-(define road-max-speed 20)
-(define road-speed road-min-speed)
-(define road-position 0)
-
 (define player-position
   (vec2 (/ (- (window-width (current-window)) vehicle-length) 2)
 	(+ (lane-y 3)
 	   (/ (- lane-height vehicle-height) 2))))
 
-(define (draw alpha)
-  (set! road-position (if (< road-position (* lane-length -1))
-			  (- (+ road-position lane-length) road-speed)
-			  (- road-position road-speed)))
-  (draw-road road-position road-start-y 5)
+;;;; Chickadee hooks
 
-  (draw-text "Turbo Racers!" (vec2 260.0 (- (window-height (current-window)) 25)))
-  (draw-text (format #f "Speed: ~smph" (* road-speed 5))
-	     (vec2 450.0 20.0))
+(define (update interval)
+  (set! road-section-position
+	(if (< road-section-position (* lane-length -1))
+	    (- (+ road-section-position lane-length) player-speed)
+	    (- road-section-position player-speed)))
+
+  (set! player-position (vec2+ player-position player-velocity)))
 
-  (set! player-position (vec2+ player-position player-velocity))
+(define (draw alpha)
+  (draw-road road-section-position road-start-y 5)
+  (draw-text "Turbo Racers!"
+	     (vec2 260.0 (- (window-height (current-window)) 25)))
+  
+  (draw-text (format #f "Speed: ~smph" (* player-speed 5))
+	     (vec2 450.0 20.0))
 
-  (draw-sprite selected-car player-position))
+  (draw-sprite player-car player-position))
+  
+  
 
 (define (key-press key modifiers repeat?)
   (if (eq? key 'w)
-      (set! player-velocity (vec2 0 car-steering-speed)))
+      (set! player-velocity (vec2 0 vehicle-steering-speed)))
   (if (eq? key 's)
-      (set! player-velocity (vec2 0 (* car-steering-speed -1))))
+      (set! player-velocity (vec2 0 (* vehicle-steering-speed -1))))
   (if (eq? key 'a)
-      (set! road-speed (max (- road-speed 1) road-min-speed)))
+      (set! player-speed (max (- player-speed 1) player-min-speed)))
   (if (eq? key 'd)
-      (set! road-speed (min (+ road-speed 1) road-max-speed)))
+      (set! player-speed (min (+ player-speed 1) player-max-speed)))
   )
 
 (define (key-release key modifiers)
-- 
cgit v1.2.3