From 2b60d14e962d7ca1e63353e60fbc54f02b77db25 Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Sat, 28 Sep 2013 16:34:28 +0000 Subject: [PATCH] overlay: use public getLandValue() method to draw landvalue overlay instead of directly accessing the landValueMem[] array git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@864 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/engine/Micropolis.java | 2 +- src/micropolisj/gui/OverlayMapView.java | 38 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/micropolisj/engine/Micropolis.java b/src/micropolisj/engine/Micropolis.java index 899d3ef..738b931 100644 --- a/src/micropolisj/engine/Micropolis.java +++ b/src/micropolisj/engine/Micropolis.java @@ -35,7 +35,7 @@ public class Micropolis * 0 is lowest land value; 250 is maximum land value. * Updated each cycle by ptlScan(). */ - public int [][] landValueMem; + int [][] landValueMem; /** * For each 2x2 section of the city, the pollution level of the city (0-255). diff --git a/src/micropolisj/gui/OverlayMapView.java b/src/micropolisj/gui/OverlayMapView.java index 30bf4f3..e8e8518 100644 --- a/src/micropolisj/gui/OverlayMapView.java +++ b/src/micropolisj/gui/OverlayMapView.java @@ -149,17 +149,6 @@ public class OverlayMapView extends JComponent return null; } - private void drawLandMap(Graphics gr) - { - int [][] A = engine.landValueMem; - - 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 drawPollutionMap(Graphics gr) { int [][] A = engine.pollutionMem; @@ -267,6 +256,26 @@ public class OverlayMapView extends JComponent //since it was performed here } + private int checkLandValueOverlay(BufferedImage img, int xpos, int ypos, int tile) + { + int v = engine.getLandValue(xpos, ypos); + Color c = getCI(v); + 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; + } + private int checkTrafficOverlay(BufferedImage img, int xpos, int ypos, int tile) { int d = engine.getTrafficDensity(xpos, ypos); @@ -346,6 +355,11 @@ public class OverlayMapView extends JComponent tile = checkTrafficOverlay(img, x, y, tile); } break; + + case LANDVALUE_OVERLAY: + tile = checkLandValueOverlay(img, x, y, tile); + break; + default: } @@ -377,8 +391,6 @@ public class OverlayMapView extends JComponent drawPoliceRadius(gr); break; case FIRE_OVERLAY: drawFireRadius(gr); break; - case LANDVALUE_OVERLAY: - drawLandMap(gr); break; case CRIME_OVERLAY: drawCrimeMap(gr); break; case POLLUTE_OVERLAY: