Hello. I'm new to programming and especially to SFML. I currently study c++ at my college and i wanted to make a match-3 game like bejeweled or huniepop. The point is that i have no idea how to do that so i tried to looking for something on the internet, so i found this:
.
Now i'm trying to understand this, and i'm not doing very good job at it.
if (click==1)
{
// mouse click
x0=pos.x/ts+1;
y0=pos.y/ts+1;
}
if (click==2)
{
x=pos.x/ts+1;
y=pos.y/ts+1;
if (abs(x-x0)+abs(y-y0)==1)
{swap(grid[y0][x0],grid[y][x]); isSwap=1; click=0;}
else click=1;
}
I suppose this function must select an element on first click and swap it with the different element on the second click, but i can't understand how does it swap them. Window size is 740x480, size of a tile on the playing field (ts) is 54x54 and size of an element is 48x48. There's also Vector2i offset(48,24) and pos = Mouse::getPosition(app)-offset;