Files
isokit/crates/isokit-script/stdlib/vehicles.rhai
T

68 lines
2.7 KiB
Plaintext

// isokit/vehicles: cars, trucks, motorbikes; optionally driving.
fn car_colours() { ["car1", "car2", "car3", "car4", "car5"] }
/// A car filling the plan rectangle; the long side is the driving axis.
fn car(x0, y0, x1, y1, cls) {
let ax = x1 - x0 >= y1 - y0;
let i = 0.9;
this.box(x0, y0, x1, y1, 0.25, 1.0, cls);
if ax {
this.box(x0 + i, y0 + 0.12, x1 - i, y1 - 0.12, 1.0, 1.5, "glassd");
} else {
this.box(x0 + 0.12, y0 + i, x1 - 0.12, y1 - i, 1.0, 1.5, "glassd");
}
this
}
fn meta_car() {
#{ label: "Car", category: "Vehicles", icon: "🚗",
help: "Faces local +x. A driving car moves along its length (in rotations where the depth sort allows it).",
props: [
#{ key: "colour", type: "choice", def: "car2", choices: car_colours(), label: "Colour" },
#{ key: "moving", type: "bool", def: false, label: "Driving" },
#{ key: "travel", type: "float", def: 25.0, min: 2.0, max: 300.0, step: 1.0, label: "Travel (m)" },
#{ key: "dur", type: "float", def: 11.0, min: 2.0, max: 120.0, step: 0.5, label: "Loop time (s)" },
] }
}
fn prefab_car(o) {
let p = o.p;
let s = sprite();
if p.moving { s.drive(p.travel, 0.0, p.dur, hash(o.x + o.y) * p.dur); }
s.car(-2.2, -0.9, 2.2, 0.9, p.colour);
if p.moving { s.end(); }
}
fn meta_truck() {
#{ label: "Truck", category: "Vehicles", icon: "🚚",
props: [
#{ key: "len", type: "float", def: 8.0, min: 5.0, max: 16.5, step: 0.5, label: "Length (m)" },
#{ key: "box", type: "choice", def: "truckbox", choices: ["truckbox", "cab", "carton", "steel"], label: "Body" },
#{ key: "moving", type: "bool", def: false, label: "Driving" },
#{ key: "travel", type: "float", def: 40.0, min: 2.0, max: 300.0, step: 1.0, label: "Travel (m)" },
#{ key: "dur", type: "float", def: 18.0, min: 2.0, max: 120.0, step: 0.5, label: "Loop time (s)" },
] }
}
fn prefab_truck(o) {
let p = o.p;
let L = p.len / 2.0;
let s = sprite();
if p.moving { s.drive(p.travel, 0.0, p.dur, hash(o.x * 3.0 + o.y) * p.dur); }
s.box(-L, -1.2, L, 1.2, 0.35, 0.95, "chassis");
s.seq([
[-0.9, 0.0, |q| q.box(-L, -1.25, L - 2.2, 1.25, 0.95, 3.6, p.box)],
[L - 1.1, 0.0, |q| { q.box(L - 2.1, -1.2, L, 1.2, 0.95, 2.9, "cab"); q.box(L - 0.12, -1.0, L, 1.0, 1.9, 2.6, "glassd"); }],
]);
if p.moving { s.end(); }
}
fn meta_moto() {
#{ label: "Motorbike", category: "Vehicles", icon: "🛵",
props: [ #{ key: "colour", type: "choice", def: "car1", choices: car_colours(), label: "Colour" } ] }
}
fn prefab_moto(o) {
let s = sprite();
s.box(-0.95, -0.3, 0.95, 0.3, 0.3, 0.85, o.p.colour);
s.person(0.0, 0.0, 0.55);
}