From bcb58e9a7d929fdda1b9b3a9e8b36ac864a70316 Mon Sep 17 00:00:00 2001 From: Gene Pasquet Date: Sun, 19 May 2024 09:20:34 +0100 Subject: Limit and display car speed --- turbo.scm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/turbo.scm b/turbo.scm index 3c5b194..367b03c 100644 --- a/turbo.scm +++ b/turbo.scm @@ -1,7 +1,8 @@ (use-modules (chickadee graphics sprite) (chickadee) (chickadee graphics viewport) - (ice-9 pretty-print)) + (ice-9 pretty-print) + (ice-9 format)) (define lane-height 65) (define lane-length 200) @@ -38,10 +39,11 @@ (define selected-car (texture-atlas-ref vehicles 0)) (define car-pos-x 0.0) -(define car-speed 4.0) -(define car-steering 4.0) +(define car-steering-speed 4.0) (define player-velocity (vec2 0 0)) -(define road-velocity 4) +(define road-min-speed 4) +(define road-max-speed 20) +(define road-speed road-min-speed) (define road-position 0) (define player-position @@ -51,11 +53,13 @@ (define (draw alpha) (set! road-position (if (< road-position (* lane-length -1)) - (- (+ road-position lane-length) road-velocity) - (- road-position road-velocity))) + (- (+ road-position lane-length) road-speed) + (- road-position road-speed))) (draw-road road-position road-start-y 5) (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)) (set! player-position (vec2+ player-position player-velocity)) @@ -63,13 +67,13 @@ (define (key-press key modifiers repeat?) (if (eq? key 'w) - (set! player-velocity (vec2 0 car-steering))) + (set! player-velocity (vec2 0 car-steering-speed))) (if (eq? key 's) - (set! player-velocity (vec2 0 (* car-steering -1)))) + (set! player-velocity (vec2 0 (* car-steering-speed -1)))) (if (eq? key 'a) - (set! road-velocity (- road-velocity 1))) + (set! road-speed (max (- road-speed 1) road-min-speed))) (if (eq? key 'd) - (set! road-velocity (+ road-velocity 1))) + (set! road-speed (min (+ road-speed 1) road-max-speed))) ) (define (key-release key modifiers) -- cgit v1.2.3