public int[] getTile(int[] mouse) {
// welches rechteck?
int recx = (int) Math.round(mouse[0] / 48);
int recy = (int) Math.round(mouse[1] / 23);
int[] pos = new int[3];
if ((mask.getRGB(mouse[0] - recx * 48, mouse[1] - recy * 23) == -1)) {
// weiss
pos[0] = recx * 2;
pos[1] = recy;
} else if ((mask.getRGB(mouse[0] - recx * 48, mouse[1] - recy * 23) == -16711936)) {
// grün
pos[0] = recx * 2 - 1;
pos[1] = recy - 1;
} else if ((mask.getRGB(mouse[0] - recx * 48, mouse[1] - recy * 23) == -256)) {
// gelb
pos[0] = recx * 2 + 1;
pos[1] = recy - 1;
} else if ((mask.getRGB(mouse[0] - recx * 48, mouse[1] - recy * 23) == -65536)) {
// rot
pos[0] = recx * 2 + 1;
pos[1] = recy;
} else if ((mask.getRGB(mouse[0] - recx * 48, mouse[1] - recy * 23) == -16776961)) {
// blau
pos[0] = recx * 2 - 1;
pos[1] = recy;
}
pos = overlappingTiles(pos, new int[]{mouse[0] - recx * 48, mouse[1] - recy * 23});
return pos;
}
private int[] overlappingTiles(int[] pos, int[] mouse) {
for (int z = this.map.length - 1; z > 0; z--) {
// X gerade oder ungerade? -> Tile versetzt oder nicht?
if (pos[0] % 2 == 0) {
// U
if (pos[1] + z < this.map[0].length) {
if (!this.map[z][pos[1] + z][pos[0]].startsWith("-,-")) {
if (mask2.getRGB(mouse[0] + 48 * Integer.parseInt(this.map[z][pos[1] + z][pos[0]].split(",")[1]), mouse[1]) == -1) {
return new int[]{pos[0], pos[1] + z, z};
}
}
}
// R
if (pos[1] + z - 1 < this.map[0].length && pos[0] + 1 < this.map[0][0].length) {
if (!this.map[z][pos[1] + z - 1][pos[0] + 1].startsWith("-,-")) {
if (mask2.getRGB(mouse[0] + 48 * Integer.parseInt(this.map[z][pos[1] + z - 1][pos[0] + 1].split(",")[1]), mouse[1] + 23) == -1) {
return new int[]{pos[0] + 1, pos[1] + z - 1, z};
}
}
}
// L
if (pos[1] + z - 1 < this.map[0].length && 0 <= pos[0] - 1) {
if (!this.map[z][pos[1] + z - 1][pos[0] - 1].startsWith("-,-")) {
if (mask2.getRGB(mouse[0] + 48 * Integer.parseInt(this.map[z][pos[1] + z - 1][pos[0] - 1].split(",")[1]), mouse[1] + 46) == -1) {
return new int[]{pos[0] - 1, pos[1] + z, z};
}
}
}
// O
if (pos[1] + z - 1 < this.map[0].length) {
if (!this.map[z][pos[1] + z - 1][pos[0]].startsWith("-,-")) {
return new int[]{pos[0], pos[1] + z - 1, z};
}
}
} else {
// U
if (pos[1] + z < this.map[0].length) {
if (!this.map[z][pos[1] + z][pos[0]].startsWith("-,-")) {
if (mask2.getRGB(mouse[0] + 48 * Integer.parseInt(this.map[z][pos[1] + z][pos[0]].split(",")[1]), mouse[1]) == -1) {
return new int[]{pos[0], pos[1] + z, z};
}
}
}
// R
if (pos[1] + z < this.map[0].length && pos[0] + 1 < this.map[0][0].length) {
if (!this.map[z][pos[1] + z][pos[0] + 1].startsWith("-,-")) {
if (mask2.getRGB(mouse[0] + 48 * Integer.parseInt(this.map[z][pos[1] + z][pos[0] + 1].split(",")[1]), mouse[1] + 23) == -1) {
return new int[]{pos[0] + 1, pos[1] + z, z};
}
}
}
// L
if (pos[1] + z < this.map[0].length && 0 <= pos[0] - 1) {
if (!this.map[z][pos[1] + z][pos[0] - 1].startsWith("-,-")) {
if (mask2.getRGB(mouse[0] + 48 * Integer.parseInt(this.map[z][pos[1] + z][pos[0] - 1].split(",")[1]), mouse[1] + 46) == -1) {
return new int[]{pos[0] - 1, pos[1] + z, z};
}
}
}
// O
if (pos[1] + z - 1 < this.map[0].length) {
if (!this.map[z][pos[1] + z - 1][pos[0]].startsWith("-,-")) {
return new int[]{pos[0], pos[1] + z - 1, z};
}
}
}
}
// nicht überdeckt
return pos;
}