Browse Source

Colors, exclude origin when choosing destination

Tyler Hallada 6 years ago
parent
commit
e686a854d8
3 changed files with 10 additions and 4 deletions
  1. 1 1
      src/Station.ts
  2. 1 1
      src/Train.ts
  3. 8 2
      src/transport.ts

+ 1 - 1
src/Station.ts

@@ -40,7 +40,7 @@ export default class Station {
40 40
     stationCount += 1;
41 41
     this.id = stationCount;
42 42
     this.label = new PIXI.Text(`${this.id}`, {
43
-      fill: 'orange',
43
+      fill: '#FFA500',
44 44
       fontFamily: 'monospace',
45 45
       fontSize: '12px',
46 46
     });

+ 1 - 1
src/Train.ts

@@ -23,7 +23,7 @@ export default class Train {
23 23
     trainCount += 1;
24 24
     this.id = trainCount;
25 25
     this.label = new PIXI.Text(`${this.id}`, {
26
-      fill: 'white',
26
+      fill: '#AEAEAE',
27 27
       fontFamily: 'monospace',
28 28
       fontSize: '12px',
29 29
     });

+ 8 - 2
src/transport.ts

@@ -70,7 +70,9 @@ const moveTrains = (trains: Train[], stations: Station[]) => {
70 70
   for (const train of trains) {
71 71
     // choose a destination randomly with a bias towards larger stations
72 72
     if (train.destination === undefined) {
73
-      const closeStations = Station.stationsWithinRadius(stations, train.location, MAX_JOURNEY);
73
+      const otherStations = stations.filter(station => station !== train.origin);
74
+      const closeStations = Station.stationsWithinRadius(otherStations, train.location,
75
+                                                         MAX_JOURNEY);
74 76
       const closeStationWeights = closeStations.map(station => station.population);
75 77
       train.destination = weightedRandom(closeStations, closeStationWeights);
76 78
     }
@@ -140,10 +142,14 @@ const run = () => {
140 142
 
141 143
     graphics.clear();
142 144
     fpsText.text = `${Math.round(ticker.FPS)}`;
143
-    graphics.lineStyle(1, 0xaeaeae, 1);
144 145
 
146
+    graphics.lineStyle(1, 0xFFA500, 1);
145 147
     drawStations(stations, graphics);
148
+
149
+    graphics.lineStyle(1, 0xAEAEAE, 1);
146 150
     drawTrains(trains, graphics);
151
+
152
+    // TODO: ?
147 153
     // drawLine(line, graphics);
148 154
   });
149 155
   ticker.start();