(define-module (turbo vehicles) #:use-module (srfi srfi-9) #:use-module (chickadee math vector) #:use-module (chickadee math rect) #:export (make-vehicle make-inactive-vehicle vehicle-height vehicle-length vehicle-steering-speed vehicle-id vehicle-sprite vehicle-position vehicle-speed vehicle-active? set-vehicle-position! set-vehicle-speed! set-vehicle-active! vehicle-hitbox vehicle-safety-distance? vehicle-speed-diff)) (define vehicle-height 45) (define vehicle-length 100) (define vehicle-steering-speed 4.0) (define-record-type (make-vehicle id sprite position speed active?) vechicle? (id vehicle-id) (sprite vehicle-sprite) (position vehicle-position set-vehicle-position!) (speed vehicle-speed set-vehicle-speed!) (active? vehicle-active? set-vehicle-active!)) (define (make-inactive-vehicle id tile initial-position) (make-vehicle id tile initial-position 4 #f)) (define (vehicle-hitbox vehicle) (rect (vec2-x (vehicle-position vehicle)) (vec2-y (vehicle-position vehicle)) vehicle-length vehicle-height)) (define (vehicle-safety-distance? vehicle1 vehicle2) (let ((vehicle1-x (vec2-x (vehicle-position vehicle1))) (vehicle2-x (vec2-x (vehicle-position vehicle2)))) (> vehicle2-x (+ (* 3 vehicle-length) vehicle1-x)))) (define (vehicle-speed-diff vehicle1 vehicle2) (abs (- (vehicle-speed vehicle1) (vehicle-speed vehicle2))))