train following

This commit is contained in:
2025-02-17 20:58:43 -07:00
parent 20e6174658
commit 7b244526b9
8 changed files with 156 additions and 15 deletions

View File

@@ -404,6 +404,7 @@ export class EditTrackState extends State<States> {
const inputManager = getContextItem<InputManager>("inputManager");
inputManager.offKey("e");
inputManager.offKey("w");
inputManager.offKey("z");
inputManager.offKey("Escape");
inputManager.offMouse("left");
if (this.heldEvents.size > 0) {

View File

@@ -1,4 +1,4 @@
import { Doodler } from "@bearmetal/doodler";
import { Doodler, Point, Vector, ZoomableDoodler } from "@bearmetal/doodler";
import { getContext, getContextItem } from "../../lib/context.ts";
import { InputManager } from "../../lib/input.ts";
import { TrackSystem } from "../../track/system.ts";
@@ -19,8 +19,20 @@ export class RunningState extends State<States> {
layers: number[] = [];
activeTrain: Train | undefined;
override update(dt: number): void {
const ctx = getContext() as { trains: Train[]; track: TrackSystem };
const doodler = getContextItem<ZoomableDoodler>(
"doodler",
);
if (this.activeTrain) {
// (doodler as any).origin = doodler.worldToScreen(
// doodler.width - this.activeTrain.aabb.center.x,
// doodler.height - this.activeTrain.aabb.center.y,
// );
doodler.centerCameraOn(this.activeTrain.aabb.center);
}
// const ctx = getContext() as { trains: DotFollower[]; track: TrackSystem };
// TODO
// Update trains
@@ -67,6 +79,7 @@ export class RunningState extends State<States> {
new LargeLadyTender(),
]);
ctx.trains.push(train);
this.activeTrain = train;
// const trainCount = 1000;
// for (let i = 0; i < trainCount; i++) {
// const train = new Train(track.path, [new LargeLady(), new Tender()]);