From a380feb559194c5f5d1e2d0287d88c633eda732f Mon Sep 17 00:00:00 2001 From: Gene Pasquet Date: Sat, 18 May 2024 15:58:12 +0100 Subject: Moving road --- turbo.scm | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/turbo.scm b/turbo.scm index 19ad423..3c5b194 100644 --- a/turbo.scm +++ b/turbo.scm @@ -35,13 +35,14 @@ (define vehicle-height 45) (define vehicle-length 100) (define vehicles (load-tileset "vehicles.png" vehicle-length vehicle-height)) -(define the-car (texture-atlas-ref vehicles 0)) -(define car-ref 0) +(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 player-velocity (vec2 0 0)) +(define road-velocity 4) +(define road-position 0) (define player-position (vec2 (/ (- (window-width (current-window)) vehicle-length) 2) @@ -49,20 +50,27 @@ (/ (- lane-height vehicle-height) 2)))) (define (draw alpha) - (draw-road 0 road-start-y 5) + (set! road-position (if (< road-position (* lane-length -1)) + (- (+ road-position lane-length) road-velocity) + (- road-position road-velocity))) + (draw-road road-position road-start-y 5) (draw-text "Turbo Racers!" (vec2 260.0 (- (window-height (current-window)) 25))) (set! player-position (vec2+ player-position player-velocity)) - (draw-sprite the-car player-position) - ) + (draw-sprite selected-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))))) + (set! player-velocity (vec2 0 (* car-steering -1)))) + (if (eq? key 'a) + (set! road-velocity (- road-velocity 1))) + (if (eq? key 'd) + (set! road-velocity (+ road-velocity 1))) + ) (define (key-release key modifiers) (if (or (eq? key 'w) (eq? key 's)) -- cgit v1.2.3