May 21, 2013 at 10:53pm May 21, 2013 at 10:53pm UTC
Writing this code that handles clicks with the left mouse button. But I want to be able to check for clicks within a 200x200 pixel area. Here's what I have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
void EGame::OnLButtonDown(int mX, int mY) {
int ID = mX / 200;
ID = ID + ((mY / 200) * 3);
if (grid[ID] != GRID_TYPE_NONE) {
return ;
}
if (currentplayer == 0) {
SetCell(ID, GRID_TYPE_X);
currentplayer = 1;
Logger::Log("X player has moved." );
}else {
SetCell(ID, GRID_TYPE_O);
currentplayer = 0;
Logger::Log("O player has moved." );
}
// Code that checks for clicks.
}
Using the width and height of the object, e.g; pX->w is width and pX->h is height
How would I check within the 200x200 area with mX and mY?
Last edited on May 21, 2013 at 10:54pm May 21, 2013 at 10:54pm UTC
May 22, 2013 at 5:29am May 22, 2013 at 5:29am UTC
@ats15
Sorry for not being clear, as the top code is fine. It's the comment line. mX and mY are the coords where the mouse clicks.