|
@@ -9,6 +9,8 @@ import './style.css';
|
9
|
9
|
const maxSpeed = 10.0;
|
10
|
10
|
const acceleration = 0.25;
|
11
|
11
|
|
|
12
|
+const trainTexts: PIXI.Text[] = [];
|
|
13
|
+
|
12
|
14
|
const isPointDistant = (point: PIXI.Point, stations: Station[], minDistance: number): boolean => {
|
13
|
15
|
for (const station of stations) {
|
14
|
16
|
if (distance(point, station.location) < minDistance) {
|
|
@@ -40,7 +42,10 @@ const initStations = (numStations: number): Station[] => {
|
40
|
42
|
|
41
|
43
|
const drawStations = (stations: Station[], graphics: PIXI.Graphics) => {
|
42
|
44
|
for (const station of stations) {
|
43
|
|
- graphics.drawCircle(station.location.x, station.location.y, station.population / 60);
|
|
45
|
+ const radius = station.population / 60;
|
|
46
|
+ graphics.drawCircle(station.location.x, station.location.y, radius);
|
|
47
|
+ station.label.x = station.location.x + radius + 1;
|
|
48
|
+ station.label.y = station.location.y + radius + 1;
|
44
|
49
|
}
|
45
|
50
|
};
|
46
|
51
|
|
|
@@ -83,8 +88,8 @@ const moveTrains = (trains: Train[], stations: Station[]) => {
|
83
|
88
|
// advance train
|
84
|
89
|
const progress = train.speed / journeyLeft;
|
85
|
90
|
train.location = new PIXI.Point(
|
86
|
|
- train.location.x + (Math.abs(train.location.x - train.destination.location.x) * progress),
|
87
|
|
- train.location.y + (Math.abs(train.location.y - train.destination.location.y) * progress),
|
|
91
|
+ train.location.x + ((train.destination.location.x - train.location.x) * progress),
|
|
92
|
+ train.location.y + ((train.destination.location.y - train.location.y) * progress),
|
88
|
93
|
);
|
89
|
94
|
}
|
90
|
95
|
};
|
|
@@ -92,6 +97,8 @@ const moveTrains = (trains: Train[], stations: Station[]) => {
|
92
|
97
|
const drawTrains = (trains: Train[], graphics: PIXI.Graphics) => {
|
93
|
98
|
for (const train of trains) {
|
94
|
99
|
graphics.drawCircle(train.location.x, train.location.y, 2);
|
|
100
|
+ train.label.x = train.location.x + 1;
|
|
101
|
+ train.label.y = train.location.y + 1;
|
95
|
102
|
}
|
96
|
103
|
};
|
97
|
104
|
|
|
@@ -118,12 +125,12 @@ const run = () => {
|
118
|
125
|
fpsText.y = 0;
|
119
|
126
|
|
120
|
127
|
// make these const
|
121
|
|
- let stations = initStations(30);
|
122
|
|
- let trains = initTrains(15, stations);
|
|
128
|
+ // let stations = initStations(30);
|
|
129
|
+ // let trains = initTrains(15, stations);
|
123
|
130
|
// let line = new Line(stations, 10);
|
124
|
131
|
|
125
|
|
- stations = initStations(30);
|
126
|
|
- trains = initTrains(15, stations);
|
|
132
|
+ const stations = initStations(30);
|
|
133
|
+ const trains = initTrains(15, stations);
|
127
|
134
|
|
128
|
135
|
ticker.stop();
|
129
|
136
|
ticker.add((deltaTime) => {
|
|
@@ -141,6 +148,13 @@ const run = () => {
|
141
|
148
|
|
142
|
149
|
app.stage.addChild(graphics);
|
143
|
150
|
app.stage.addChild(fpsText);
|
|
151
|
+ // Add debug labels
|
|
152
|
+ for (const train of trains) {
|
|
153
|
+ app.stage.addChild(train.label);
|
|
154
|
+ }
|
|
155
|
+ for (const station of stations) {
|
|
156
|
+ app.stage.addChild(station.label);
|
|
157
|
+ }
|
144
|
158
|
document.body.appendChild(app.view);
|
145
|
159
|
|
146
|
160
|
window.addEventListener('resize', () => {
|