Skip to content

Commit

Permalink
final fixes lightsensor
Browse files Browse the repository at this point in the history
  • Loading branch information
Florjohn committed Nov 16, 2011
1 parent 4d3c4a5 commit 4a819fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
51 changes: 27 additions & 24 deletions src/java/penoplatinum/simulator/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
import java.net.URL;

public class Board extends JPanel {

static final int LINE_ORIGIN = 40;
static final int TILE_WIDTH_AND_LENGTH = 160;
static final int LINE_PIXEL_WIDTH = 2;
static final int BARCODE_PIXEL_WIDTH = 4;
private Image robot;
private Map map;
private int direction = 0;
Expand Down Expand Up @@ -73,8 +76,8 @@ private void prepareTracking() {
}

private BufferedImage createBuffer() {
int w = this.map.getWidth() * 160;
int h = this.map.getHeight() * 160;
int w = this.map.getWidth() * TILE_WIDTH_AND_LENGTH;
int h = this.map.getHeight() * TILE_WIDTH_AND_LENGTH;
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
}

Expand Down Expand Up @@ -112,7 +115,7 @@ private void renderTile(Graphics2D g2d, Tile tile, int left, int top) {
// tile = 80 cm, scale = 2px/cm
// background
g2d.setColor(new Color(205,165,100));
g2d.fill(new Rectangle(160*(left-1), 160*(top-1), 160, 160));
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1), TILE_WIDTH_AND_LENGTH*(top-1), TILE_WIDTH_AND_LENGTH,TILE_WIDTH_AND_LENGTH));

this.renderLines ( g2d, tile, left, top );
this.renderBarcode ( g2d, tile, left, top );
Expand All @@ -128,33 +131,33 @@ private void renderLines(Graphics2D g2d, Tile tile, int left, int top) {
g2d.setColor(tile.hasLine(Baring.N, Tile.WHITE) ?
this.WHITE : this.BLACK);
width = 158; offset = 0;
if( tile.hasLine(Baring.W) ) { width -= 40; offset += 40; }
if( tile.hasLine(Baring.E) ) { width -= 40; }
g2d.fill(new Rectangle(160*(left-1)+offset, 160*(top-1)+40, width, 2));
if( tile.hasLine(Baring.W) ) { width -= LINE_ORIGIN; offset += LINE_ORIGIN; }
if( tile.hasLine(Baring.E) ) { width -= LINE_ORIGIN; }
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1)+offset, TILE_WIDTH_AND_LENGTH*(top-1)+LINE_ORIGIN, width, LINE_PIXEL_WIDTH));
}
if( tile.hasLine(Baring.E) ) {
g2d.setColor(tile.hasLine(Baring.E, Tile.WHITE) ?
this.WHITE : this.BLACK);
width = 158; offset = 0;
if( tile.hasLine(Baring.N) ) { width -= 40; offset += 40; }
if( tile.hasLine(Baring.S) ) { width -= 40; }
g2d.fill(new Rectangle(160*(left)-44, 160*(top-1)+offset, 2, width));
if( tile.hasLine(Baring.N) ) { width -= LINE_ORIGIN; offset += LINE_ORIGIN; }
if( tile.hasLine(Baring.S) ) { width -= LINE_ORIGIN; }
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left)-4 -LINE_ORIGIN, TILE_WIDTH_AND_LENGTH*(top-1)+offset,LINE_PIXEL_WIDTH, width));
}
if( tile.hasLine(Baring.S) ) {
g2d.setColor(tile.hasLine(Baring.S, Tile.WHITE) ?
this.WHITE : this.BLACK);
width = 158; offset = 0;
if( tile.hasLine(Baring.W) ) { width -= 40; offset += 40; }
if( tile.hasLine(Baring.E) ) { width -= 40; }
g2d.fill(new Rectangle(160*(left-1)+offset, 160*(top)-44, width, 2));
if( tile.hasLine(Baring.W) ) { width -= LINE_ORIGIN; offset += LINE_ORIGIN; }
if( tile.hasLine(Baring.E) ) { width -= LINE_ORIGIN; }
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1)+offset, TILE_WIDTH_AND_LENGTH*(top)-4 -LINE_ORIGIN, width,LINE_PIXEL_WIDTH));
}
if( tile.hasLine(Baring.W) ) {
g2d.setColor(tile.hasLine(Baring.W, Tile.WHITE) ?
this.WHITE : this.BLACK);
width = 158; offset = 0;
if( tile.hasLine(Baring.N) ) { width -= 40; offset += 40; }
if( tile.hasLine(Baring.S) ) { width -= 40; }
g2d.fill(new Rectangle(160*(left-1)+40, 160*(top-1)+offset, 2, width));
if( tile.hasLine(Baring.N) ) { width -= LINE_ORIGIN; offset += LINE_ORIGIN; }
if( tile.hasLine(Baring.S) ) { width -= LINE_ORIGIN; }
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1)+LINE_ORIGIN, TILE_WIDTH_AND_LENGTH*(top-1)+offset,LINE_PIXEL_WIDTH, width));
}
}

Expand All @@ -166,16 +169,16 @@ private void renderBarcode(Graphics2D g2d, Tile tile, int left, int top) {

switch( tile.getBarcodeLocation() ) {
case Baring.N:
g2d.fill(new Rectangle(160*(left-1), 160*(top-1)+4*(line), 160, 4));
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1), TILE_WIDTH_AND_LENGTH*(top-1)+4*(line), TILE_WIDTH_AND_LENGTH, BARCODE_PIXEL_WIDTH));
break;
case Baring.E:
g2d.fill(new Rectangle(160*(left)-4*(line+1), 160*(top-1), 4, 160));
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left)-4*(line+1), TILE_WIDTH_AND_LENGTH*(top-1), BARCODE_PIXEL_WIDTH, TILE_WIDTH_AND_LENGTH));
break;
case Baring.S:
g2d.fill(new Rectangle(160*(left-1), 160*(top)-4*(line+1), 160, 4));
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1), TILE_WIDTH_AND_LENGTH*(top)-4*(line+1), TILE_WIDTH_AND_LENGTH, BARCODE_PIXEL_WIDTH));
break;
case Baring.W:
g2d.fill(new Rectangle(160*(left-1)+4*line, 160*(top-1)+4, 4, 160));
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1)+4*line, TILE_WIDTH_AND_LENGTH*(top-1)+4, BARCODE_PIXEL_WIDTH, TILE_WIDTH_AND_LENGTH));
break;
}
}
Expand All @@ -189,16 +192,16 @@ private void renderWalls(Graphics2D g2d, Tile tile, int left, int top) {
// walls are 2cm width = 4px
g2d.setColor(new Color(100,53,38));
if( tile.hasWall(Baring.N) ) {
g2d.fill(new Rectangle(160*(left-1), 160*(top-1), 160, 4));
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1), TILE_WIDTH_AND_LENGTH*(top-1), TILE_WIDTH_AND_LENGTH, 4));
}
if( tile.hasWall(Baring.E) ) {
g2d.fill(new Rectangle(160*(left)-4, 160*(top-1), 4, 160));
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left)-4, TILE_WIDTH_AND_LENGTH*(top-1), 4, TILE_WIDTH_AND_LENGTH));
}
if( tile.hasWall(Baring.S) ) {
g2d.fill(new Rectangle(160*(left-1), 160*(top)-4, 160, 4));
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1), TILE_WIDTH_AND_LENGTH*(top)-4, TILE_WIDTH_AND_LENGTH, 4));
}
if( tile.hasWall(Baring.W) ) {
g2d.fill(new Rectangle(160*(left-1), 160*(top-1), 4, 160));
g2d.fill(new Rectangle(TILE_WIDTH_AND_LENGTH*(left-1),TILE_WIDTH_AND_LENGTH*(top-1), 4, TILE_WIDTH_AND_LENGTH));
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/java/penoplatinum/simulator/ConsoleSimulationView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public void showMap(Map map) {
// this method is intentionally left blank
// no map required on console ;-)
}

@Override
public void log(String msg) {
throw new UnsupportedOperationException("Not supported yet.");
}
}

0 comments on commit 4a819fa

Please sign in to comment.