Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Match-3 token swap  (Read 1373 times)

0 Members and 1 Guest are viewing this topic.

Glinvan

  • Newbie
  • *
  • Posts: 2
    • View Profile
Match-3 token swap
« on: March 25, 2018, 10:27:33 pm »
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;

Glinvan

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Match-3 token swap
« Reply #1 on: March 28, 2018, 12:19:08 am »
Ok, i decided to rewrite this code by myself, maybe that will help me understand it better. I don't understand what is this offset used for. It's declared like this: Vector2i offset(48,24); and it's used in this: gems.move(offset.x-ts,offset.y-ts);

 

anything