Trains on tracks with left and right pathing
This commit is contained in:
@@ -3,6 +3,7 @@ import { InputManager } from "../../lib/input.ts";
|
||||
import { TrackSystem } from "../../track/system.ts";
|
||||
import { Tender } from "../../train/cars.ts";
|
||||
import { RedEngine } from "../../train/engines.ts";
|
||||
import { DotFollower } from "../../train/newTrain.ts";
|
||||
import { Train } from "../../train/train.ts";
|
||||
import { State } from "../machine.ts";
|
||||
import { States } from "./index.ts";
|
||||
@@ -15,6 +16,8 @@ export class RunningState extends State<States> {
|
||||
]);
|
||||
override update(dt: number): void {
|
||||
const ctx = getContext() as { trains: Train[]; track: TrackSystem };
|
||||
// const ctx = getContext() as { trains: DotFollower[]; track: TrackSystem };
|
||||
const input = getContextItem<InputManager>("inputManager");
|
||||
// TODO
|
||||
// Update trains
|
||||
// Update world
|
||||
@@ -22,6 +25,9 @@ export class RunningState extends State<States> {
|
||||
// Draw (maybe via a layer system that syncs with doodler)
|
||||
ctx.track.draw();
|
||||
for (const train of ctx.trains) {
|
||||
// if (input.getKeyState("ArrowUp")) {
|
||||
// train.acceleration.x += 10;
|
||||
// }
|
||||
train.move(dt);
|
||||
train.draw();
|
||||
}
|
||||
@@ -32,7 +38,11 @@ export class RunningState extends State<States> {
|
||||
const inputManager = getContextItem<InputManager>("inputManager");
|
||||
const track = getContextItem<TrackSystem>("track");
|
||||
const ctx = getContext() as { trains: Train[] };
|
||||
// const ctx = getContext() as { trains: DotFollower[] };
|
||||
inputManager.onKey(" ", () => {
|
||||
// const path = track.path;
|
||||
// const follower = new DotFollower(path, path.points[0].copy());
|
||||
// ctx.trains.push(follower);
|
||||
const train = new Train(track.path, [new RedEngine(), new Tender()]);
|
||||
ctx.trains.push(train);
|
||||
});
|
||||
|
Reference in New Issue
Block a user