Got it working
It doesn't look good when the camera is tilted as it draws the screen and not the game world obviously.
But it works.
private List<Position> tiles = new ArrayList<>();
@Override
public void mouseDragged(MouseEvent e) {
handle(e);
}
@Override
public void mouseClicked(MouseEvent e) {
handle(e);
}
private void handle(MouseEvent e) {
log(e.getX() + ", " + e.getY());
Position pos = getPosition(e.getPoint());
if (exists(pos)) {
tiles.remove(pos);
return;
}
tiles.add(pos);
}
@Override
public void onPaint(Graphics2D graphics) {
Graphics2D g = (Graphics2D) graphics;
g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF));
g.setColor(Color.GREEN);
if (!tiles.isEmpty()) {
for (Position t : tiles) {
if (t.isVisible(getBot())) {
g.draw(t.getPolygon(getBot()).getBounds());
}
}
}
}
private Position getPosition(Point mousePosition) {
for(int x = 0; x < 104; x++) {
for(int y = 0; y < 104; y++) {
Position pos = new Position(getMap().getBaseX()+x, getMap().getBaseY()+y, getMap().getPlane());
if(pos.isVisible(getBot()) && pos.getPolygon(getBot()).contains(mousePosition)) {
return pos;
}
}
}
return null;
}
private boolean exists(Position pos) {
if (!tiles.isEmpty()) {
for (Position tile : tiles) {
if (tile.equals(pos)) {
return true;
}
}
}
return false;
}