overlay: use public getTrafficDensity() method to draw traffic overlay
git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@860 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
b18b51d08e
commit
99954a3619
2 changed files with 25 additions and 14 deletions
|
@ -63,7 +63,7 @@ public class Micropolis
|
|||
* If between 64 and 192, then the "light traffic" animation is used.
|
||||
* If 192 or higher, then the "heavy traffic" animation is used.
|
||||
*/
|
||||
public int [][] trfDensity;
|
||||
int [][] trfDensity;
|
||||
|
||||
// quarter-size arrays
|
||||
|
||||
|
|
|
@ -182,17 +182,6 @@ public class OverlayMapView extends JComponent
|
|||
}
|
||||
}
|
||||
|
||||
private void drawTrafficMap(Graphics gr)
|
||||
{
|
||||
int [][] A = engine.trfDensity;
|
||||
|
||||
for (int y = 0; y < A.length; y++) {
|
||||
for (int x = 0; x < A[y].length; x++) {
|
||||
maybeDrawRect(gr, getCI(A[y][x]),x*6,y*6,6,6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPopDensity(Graphics gr)
|
||||
{
|
||||
int [][] A = engine.popDensity;
|
||||
|
@ -278,6 +267,26 @@ public class OverlayMapView extends JComponent
|
|||
//since it was performed here
|
||||
}
|
||||
|
||||
private int checkTrafficOverlay(BufferedImage img, int xpos, int ypos, int tile)
|
||||
{
|
||||
int d = engine.getTrafficDensity(xpos, ypos);
|
||||
Color c = getCI(d);
|
||||
if (c == null) {
|
||||
return tile;
|
||||
}
|
||||
|
||||
int pix = c.getRGB();
|
||||
for (int yy = 0; yy < TILE_HEIGHT; yy++) {
|
||||
for (int xx = 0; xx < TILE_WIDTH; xx++) {
|
||||
img.setRGB(
|
||||
xpos*TILE_WIDTH+xx,
|
||||
ypos*TILE_HEIGHT+yy,
|
||||
pix);
|
||||
}
|
||||
}
|
||||
return CLEAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics gr)
|
||||
{
|
||||
|
@ -332,6 +341,10 @@ public class OverlayMapView extends JComponent
|
|||
{
|
||||
tile = DIRT;
|
||||
}
|
||||
if (mapState == MapState.TRAFFIC_OVERLAY)
|
||||
{
|
||||
tile = checkTrafficOverlay(img, x, y, tile);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
@ -370,8 +383,6 @@ public class OverlayMapView extends JComponent
|
|||
drawCrimeMap(gr); break;
|
||||
case POLLUTE_OVERLAY:
|
||||
drawPollutionMap(gr); break;
|
||||
case TRAFFIC_OVERLAY:
|
||||
drawTrafficMap(gr); break;
|
||||
case GROWTHRATE_OVERLAY:
|
||||
drawRateOfGrowth(gr); break;
|
||||
case POPDEN_OVERLAY:
|
||||
|
|
Reference in a new issue