I've created a hexagon, but I'm stumped as to how I would detect if the mouse has entered within its specific boundaries. I thought that perhaps something along the lines of:
might suffice, however I am planning on placing these hexagons into a grid of hexagons. This would, of course, result in either a dead zone between hexagons, or 2 hexagons being selected.
So, any ideas?
Below is the code to create a single hexagon, with a boolean "userClicked" within the hex class waiting for the magic code to solve this issue. Thanks in advance everyone!
int w = 500;
int h = 500;
Hex hex = new Hex (w/2, h/2, 50, 50);
//Top left point.
sideB_x = hexWidth*-1;
sideB_y = (hexHeight*-0.5);
//Bottom left point.
sideC_x = hexWidth*-1;
sideC_y = hexHeight/2;
//Bottom point.
sideD_x = 0;
sideD_y = hexHeight;
//Bottom right point.
sideE_x = hexWidth;
sideE_y = hexHeight/2;
//Top right point.
sideF_x = hexWidth;
sideF_y = (hexHeight*-1) /2;
stroke(0);
strokeWeight(2);
//
//Attention! This is the problem part.
//
if (mousePressed && dist (mouseX, mouseY, x, y) < hexWidth || dist (mouseX, mouseY, x, y) < hexHeight) {
fill (0, hexColor, 0);
}
else {
fill (255);
}
//
//Attention! The problem part is above.
//