From 1b174b77cfb7645fa1cda1eafb44d42497af8864 Mon Sep 17 00:00:00 2001 From: Gene Pasquet Date: Wed, 22 May 2024 17:00:26 +0100 Subject: Engine sound and code clean-up --- turbo/vehicles.scm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'turbo') diff --git a/turbo/vehicles.scm b/turbo/vehicles.scm index 62b6a02..68d6ced 100644 --- a/turbo/vehicles.scm +++ b/turbo/vehicles.scm @@ -12,12 +12,14 @@ vehicle-position vehicle-speed vehicle-active? + vehicle-inactive? set-vehicle-position! set-vehicle-speed! set-vehicle-active! vehicle-hitbox vehicle-safety-distance? - vehicle-speed-diff)) + vehicle-speed-diff + vehicle-move!)) (define vehicle-height 45) (define vehicle-length 100) @@ -44,9 +46,16 @@ (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)))) + (> (abs (- vehicle2-x vehicle1-x)) + (+ (* 3 vehicle-length))))) (define (vehicle-speed-diff vehicle1 vehicle2) (abs (- (vehicle-speed vehicle1) (vehicle-speed vehicle2)))) + +(define (vehicle-move! vehicle translation) + (set-vehicle-position! + vehicle + (vec2+ (vehicle-position vehicle) translation))) + +(define (vehicle-inactive? vehicle) + (not (vehicle-active? vehicle))) -- cgit v1.2.3