First-off the red numbers are wrong.
[0,0] = 0
[0,1] = 1
[0,2] = 2
And not only are they wrong, they are meaningless. The black numbers are what you actually store (in tiles).
The only difference between this and what I already gave you is that you need to convert the mouse coordinates into rectangular coordinates first, which is simple.
The origin is at the top of square [0,0]. That is X = 0, Y = 0.
The diamond increases 2 pixels along the X (as you go from the origin to the right of the screen, every 2 pixels right you go the diamond goes down the screen 1 pixel).
So start by getting the Y.
Let’s say the origin is at screen coordinate [300,25] and we click at [338,70] (with screen coordinates [0,0] being the upper-left corner).
Get the Y first.
The X coordinate is 38 pixels to the right of the origin, and for every 2 horizontal pixels it moves vertically down by 1, so 38 ÷ 2 = 19.
The adjusted Y coordinate is 29.
Now get the X.
The Y is 45 units below the board origin, and for every pixel down, 2 pixels are going to the right. So 45 × 2 = 90, which is the adjusted X.
int tiles; // Board is 5 tiles wide and 5 tiles tall. You can make it any size you want.
Click.Pos = 19×90.
Clicked tile X = 19 / 32 = 0.
Clicked tile Y = 90 / 32 = 2.
Clicked tile = tiles.
Edited by L. Spiro, 12 December 2013 - 06:32 AM.
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums