(use-modules (chickadee graphics sprite) (chickadee) (chickadee graphics viewport) (ice-9 pretty-print) (ice-9 format)) (define lane-height 65) (define lane-length 200) (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 (draw-lanes x y num-lanes) (if (> num-lanes 0) (begin (draw-sprite road-lane (vec2 x y)) (draw-lanes x (+ lane-height y) (- num-lanes 1))))) (define (draw-road-section startx starty num-lanes) (draw-sprite road-bottom (vec2 startx starty)) (draw-lanes startx (+ lane-height starty) (- num-lanes 2)) (draw-sprite road-top (vec2 startx (+ starty (* lane-height (- num-lanes 1)))))) (define (draw-road startx starty num-lanes) (if (< startx (window-width (current-window))) (begin (draw-road-section startx starty num-lanes) (draw-road (+ startx lane-length) starty num-lanes)))) (define (lane-y num-lane) (+ 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) (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)) (draw-sprite selected-car player-position)) (define (key-press key modifiers repeat?) (if (eq? key 'w) (set! player-velocity (vec2 0 car-steering-speed))) (if (eq? key 's) (set! player-velocity (vec2 0 (* car-steering-speed -1)))) (if (eq? key 'a) (set! road-speed (max (- road-speed 1) road-min-speed))) (if (eq? key 'd) (set! road-speed (min (+ road-speed 1) road-max-speed))) ) (define (key-release key modifiers) (if (or (eq? key 'w) (eq? key 's)) (set! player-velocity (vec2 0 0))))