From a2810e35feda4cd6138e020f6c89daf4aefef423 Mon Sep 17 00:00:00 2001
From: Gene Pasquet <dev@etenil.net>
Date: Sun, 26 May 2024 12:15:54 +0100
Subject: Create bundles

---
 turbo.scm | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

(limited to 'turbo.scm')

diff --git a/turbo.scm b/turbo.scm
index f2b5b07..2a9f3d3 100644
--- a/turbo.scm
+++ b/turbo.scm
@@ -1,12 +1,59 @@
 (use-modules (chickadee graphics sprite)
 	     (chickadee)
 	     (chickadee graphics viewport)
+	     (chickadee math vector)
+	     (chickadee math rect)
+	     (srfi srfi-9)
 	     (chickadee audio)
 	     (ice-9 pretty-print)
 	     (ice-9 format)
-	     (turbo vehicles)
 	     (srfi srfi-1))
 
+
+;;;; Vehicles module
+(define vehicle-height 44)
+(define vehicle-length 100)
+(define vehicle-steering-speed 4.0)
+
+(define-record-type <vehicle>
+  (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))))
+    (> (abs (- vehicle2-x vehicle1-x))
+       (+ (* 3 vehicle-length)))))
+
+(define (vehicle-speed- vehicle1 vehicle2)
+  (- (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)))
+
+(define (vehicle= vehicle1 vehicle2)
+  (= (vehicle-id vehicle1) (vehicle-id vehicle2)))
+;;;; End vehicles module
+
 ;;;; Constants and variables
 
 (define the-font (load-bitmap-font "fonts/thick_8x8.xml"))
-- 
cgit v1.2.3