track drawing and shape tweaks, train controls, fps counter, non-looping
This commit is contained in:
@@ -24,7 +24,6 @@ export class Train {
|
||||
this.t = 0;
|
||||
const resources = getContextItem<ResourceManager>("resources");
|
||||
this.cars = cars;
|
||||
console.log(track);
|
||||
// this.cars.push(
|
||||
// new TrainCar(
|
||||
// 55,
|
||||
@@ -42,19 +41,31 @@ export class Train {
|
||||
// ),
|
||||
// );
|
||||
let currentOffset = 0;
|
||||
for (const car of this.cars) {
|
||||
currentOffset += this.spacing;
|
||||
const a = this.path.followEvenPoints(this.t - currentOffset);
|
||||
currentOffset += car.length;
|
||||
const b = this.path.followEvenPoints(this.t - currentOffset);
|
||||
car.points = [a, b];
|
||||
this.nodes.push(a, b);
|
||||
// this.cars.push(car);
|
||||
try {
|
||||
for (const car of this.cars) {
|
||||
currentOffset += this.spacing;
|
||||
const a = this.path.followEvenPoints(this.t - currentOffset);
|
||||
currentOffset += car.length;
|
||||
const b = this.path.followEvenPoints(this.t - currentOffset);
|
||||
car.points = [a, b];
|
||||
this.nodes.push(a, b);
|
||||
}
|
||||
} catch {
|
||||
currentOffset = 0;
|
||||
for (const car of this.cars.toReversed()) {
|
||||
currentOffset += this.spacing;
|
||||
const a = this.path.followEvenPoints(this.t - currentOffset);
|
||||
currentOffset += car.length;
|
||||
const b = this.path.followEvenPoints(this.t - currentOffset);
|
||||
car.points = [a, b];
|
||||
this.nodes.push(a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
move(dTime: number) {
|
||||
this.t = (this.t + this.speed * dTime * 10) % this.path.evenPoints.length;
|
||||
this.t = this.t + this.speed * dTime * 10;
|
||||
// % this.path.evenPoints.length; // This should probably be on the track system
|
||||
// console.log(this.t);
|
||||
let currentOffset = 0;
|
||||
for (const car of this.cars) {
|
||||
@@ -69,27 +80,27 @@ export class Train {
|
||||
// this.draw();
|
||||
}
|
||||
|
||||
draw() {
|
||||
const doodler = getContextItem<Doodler>("doodler");
|
||||
this.path.draw();
|
||||
for (const [i, node] of this.nodes.entries()) {
|
||||
// doodler.drawCircle(node, 10, { color: "purple", weight: 3 });
|
||||
doodler.fillCircle(node, 2, { color: "purple" });
|
||||
// const next = this.nodes[i + 1];
|
||||
// if (next) {
|
||||
// const to = Vector.sub(node.point, next.point);
|
||||
// to.setMag(40);
|
||||
// doodler.line(next.point, Vector.add(to, next.point))
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
// draw() {
|
||||
// for (const car of this.cars) {
|
||||
// car.draw();
|
||||
// const doodler = getContextItem<Doodler>("doodler");
|
||||
// this.path.draw();
|
||||
// for (const [i, node] of this.nodes.entries()) {
|
||||
// // doodler.drawCircle(node, 10, { color: "purple", weight: 3 });
|
||||
// doodler.fillCircle(node, 2, { color: "purple" });
|
||||
// // const next = this.nodes[i + 1];
|
||||
// // if (next) {
|
||||
// // const to = Vector.sub(node.point, next.point);
|
||||
// // to.setMag(40);
|
||||
// // doodler.line(next.point, Vector.add(to, next.point))
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
|
||||
draw() {
|
||||
for (const car of this.cars) {
|
||||
car.draw();
|
||||
}
|
||||
}
|
||||
|
||||
real2Track(length: number) {
|
||||
return length / this.path.pointSpacing;
|
||||
}
|
||||
|
Reference in New Issue
Block a user